1 8 2 2 100 4 4 100 2
400
</pre><pre name="code" class="cpp">#include<iostream> #include<cstring> using namespace std; #define M 105 int d[M]; int main(){ int t; cin>>t; while(t--){ int n,m; cin>>m>>n; int i,j; int a[M],b[M],c[M]; for(i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i]; memset(d,0,sizeof d); for(i=1;i<=n;i++) for(int k=1;k<=c[i];k++) for(j=m;j>=a[i];j--) d[j]=max(d[j],d[j-a[i]]+b[i]); cout<<d[m]<<endl; } return 0; }
原文地址:http://blog.csdn.net/hyccfy/article/details/42878331