思路:把多重背包转化为0-1背包来做。。
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
int v[510];
int dp[101];
int w[510];
int main()
{
int T;
cin>>T;
while(T--)
{ int V,n;
cin>>V>>n;
memset(dp,0,sizeof(dp));
memset(v,0,sizeof(v));
memset(w,0,sizeof(w));
int tot=0;
for(int i=0;i!=n;++i)
{
int a,b,c;
cin>>a>>b>>c;
int t=1;
while(2*t<c+1)
{
v[tot]=t*a;
w[tot++]=t*b;
t=2*t;
}
v[tot]=(c+1-t)*a;
w[tot++]=(c+1-t)*b;
}
for(int i=0;i<tot;++i)
{
if(v[i]>V) continue;
for(int j=V;j>=v[i];--j)
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
}
cout<<dp[V]<<endl;
} return 0;
}