1 #include <iostream>
2 #include <cstdio>
3 #include <string>
4 #include <algorithm>
5 using namespace std;
6 const int N=100;
7 int main()
8 {
9 int v[N]={0,8,10,6,3,7,2};
10 int w[N]={0,4,6,2,2,5,1};
11
12 int m[N][N];
13 int n=6,c=12;
14 memset(m,0,sizeof(m));
15 for(int i=1;i<=n;i++)
16 {
17 for(int j=1;j<=c;j++)
18 {
19 if(j>=w[i])
20 m[i][j]=max(m[i-1][j],m[i-1][j-w[i]]+v[i]);
21 else
22 m[i][j]=m[i-1][j];
23 }
24 }
25
26 for(int i=1;i<=n;i++)
27 {
28 for(int j=1;j<=c;j++)
29 {
30 cout<<m[i][j]<<' ';
31 }
32 cout<<endl;
33 }
34
35 return 0;
36 }