算法.分组背包

#include
using namespace std;
const int N = 110;
int n, m, v[N], w[N], dp[N],s;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        for (int j = 1; j <= s; j++)
        {
            cin >> v[j] >> w[j];

        }
        for (int j = m; j >= v[i]; j--)
        {
            for (int k = 0; k < s; k++)
            {
                if(j>w[k]) dp[j] = max(dp[j], dp[j - w[k]] + v[k]);

               
            }
        }
    }
    cout << dp[m];

    return 0;
}

你可能感兴趣的:(算法,算法,c++,图论)