1270:【例9.14】混合背包
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 const int N=205; 6 int a[N],b[N],c[N],f[N][N]; 7 int main(){ 8 int m,n; 9 cin>>m>>n; 10 for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i]; 11 for(int i=1;i<=n;i++) 12 for(int j=1;j<=m;j++) 13 for(int k=0;k<=j/a[i]&&(k<=c[i]||!c[i]);k++) 14 f[i][j]=max(f[i][j],b[i]*k+f[i-1][j-a[i]*k]); 15 cout<<f[n][m]; 16 return 0; 17 }