开始学背包问题~
最基本的01背包终于看懂了
#include<iostream>
#include<set>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int const MAX = 1005;
int main()
{
int t, n, v;
cin >> t;
int val[MAX], vol[MAX],m[MAX];
for (int i = 0; i < t; i++)
{
cin >> n >> v;
memset(m, 0, sizeof(m));
for (int j = 1; j <= n; j++)
{
cin >> val[j];
}
for (int j = 1; j <= n; j++)
{
cin >> vol[j];
}
for (int k = 1; k <= n; k++)
{
for (int vw = v; vw >= vol[k]; vw--)
{
m[vw] = max(m[vw], m[vw - vol[k]] + val[k]);
}
}
cout << m[v] << endl;
}
system("pause");
return 0;
}