HDU_2191_多重背包

http://acm.hdu.edu.cn/showproblem.php?pid=2191

简单多重背包题。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m,p[105],h[105],c[105],ans[105];

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        memset(ans,0,sizeof(ans));
        cin >> n >> m;
        for(int i = 1;i <= m;i++)    cin >> p[i] >> h[i] >> c[i];
        for(int i = 1;i <= m;i++)
        {
            for(int j = 1;j <= c[i];j++)
            {
                for(int k = n;k >= p[i];k--)    ans[k] = max(ans[k],ans[k-p[i]]+h[i]);
            }
        }
        cout << ans[n] << endl;
    }
    return 0;
} 
原文地址:https://www.cnblogs.com/zhurb/p/5877777.html