|
|
|
|
#include<iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int n, C, i, j;
|
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뱳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
cin >> C;
|
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
cin >> n;
|
|
|
|
|
int *w = new int[n+1]; //<2F>洢<EFBFBD><E6B4A2>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int *v = new int[n+1]; //<2F>洢<EFBFBD><E6B4A2>Ʒ<EFBFBD>ļ<EFBFBD>ֵ
|
|
|
|
|
int *x = new int[n+1]; //<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ӽṹ
|
|
|
|
|
int **V = new int*[n+1]; //<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>¼
|
|
|
|
|
for (i = 0; i < n + 1; i++)
|
|
|
|
|
{
|
|
|
|
|
V[i] = new int[C + 1];
|
|
|
|
|
}
|
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
w[0] = 0;
|
|
|
|
|
for (i = 1; i < n + 1; i++) //<2F><><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>1<EFBFBD><31>ʼ<EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
cin >> w[i];
|
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD>Ʒ<EFBFBD>ļ<EFBFBD>ֵ<EFBFBD><EFBFBD>";
|
|
|
|
|
v[0] = 0;
|
|
|
|
|
for (i = 1; i < n + 1; i++)
|
|
|
|
|
cin >> v[i];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n + 1; i++)//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>0<EFBFBD><30>
|
|
|
|
|
V[i][0] = 0;
|
|
|
|
|
for (j = 0; j < C + 1; j++)//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>0<EFBFBD><30>
|
|
|
|
|
V[0][j] = 0;<EFBFBD><EFBFBD>
|
|
|
|
|
for (i = 1; i <= n; i++)
|
|
|
|
|
for (j = 1; j <= C; j++)
|
|
|
|
|
{
|
|
|
|
|
if (j < w[i])
|
|
|
|
|
V[i][j] = V[i - 1][j];
|
|
|
|
|
else
|
|
|
|
|
V[i][j] = V[i - 1][j] > (V[i - 1][j - w[i]] + v[i]) ? V[i - 1][j] : (V[i - 1][j - w[i]] + v[i]);
|
|
|
|
|
}
|
|
|
|
|
for (j = C, i = n; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (V[i][j] > V[i - 1][j])
|
|
|
|
|
{
|
|
|
|
|
x[i] = 1;
|
|
|
|
|
j = j - w[i];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
x[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ*/
|
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ž<EFBFBD>Ϊ<EFBFBD><EFBFBD>X={";
|
|
|
|
|
for (i = 1; i < n; i++)
|
|
|
|
|
cout << x[i] << ",";
|
|
|
|
|
cout << x[i] << "}" << endl;
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
/*<2A><><EFBFBD>Ʊ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ*/
|
|
|
|
|
cout << '\t';
|
|
|
|
|
for (j = 0; j < C+1; j++)
|
|
|
|
|
cout << j << '\t';
|
|
|
|
|
cout << endl;
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>кͱ<D0BA><CDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
for (i = 0; i < n + 1; i++)
|
|
|
|
|
{
|
|
|
|
|
cout << i << '\t';//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for (j = 0; j < C + 1; j++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
cout << V[i][j] << '\t';
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
delete[] w;
|
|
|
|
|
delete[] v;
|
|
|
|
|
delete[] x;
|
|
|
|
|
delete[] V;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|