标签:
1 8 2 2 100 4 4 100 2
400
//hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct inin
{
int p,h;
}a[105];
int bag[2005];
int main()
{
int T;
int n,m;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
memset(bag,0,sizeof(bag));
scanf("%d%d",&n,&m);
int u,v,w,t=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
for(int j=1;j<=w;j++)
{
t++;
a[t].p=u;
a[t].h=v;
}
}
for(int i=1;i<=t;i++)
{
for(int j=n;j>=a[i].p;j--)
{
bag[j]=max(bag[j],bag[j-a[i].p]+a[i].h);
}
}
printf("%d\n",bag[n]);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
hpu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 【多重背包模板】
标签:
原文地址:http://blog.csdn.net/dxx_111/article/details/48029671