#include<iostream>
#include<set>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int const MAX = 3403;
int main()
{
int n, m;
int w[MAX], d[MAX];
int last[MAX*4];
memset(w, 0, sizeof(w));
memset(d, 0, sizeof(d));
while (scanf_s("%d %d", &n, &m) != EOF)
{
for (int i = 1; i <= n; i++)
{
cin >> w[i] >> d[i];
}
memset(last, 0, sizeof(last));
for (int i = 1; i <= n; i++)
{
for (int ww = m; ww >= w[i]; ww--)
{
last[ww] = max(last[ww],last[ww-w[i]]+d[i]);
//if (last[ww] < last[ww - w[i]] + d[i])
// last[ww] = last[ww - w[i]] + d[i];
}
}
cout << last[m] << endl;
}
system("pause");
return 0;
}
还是很简单的题目,却错了这里
last[ww] = max(last[ww],last[ww-w[i]]+d[i]);
这里w[i]弄错了,之前写成了w[i-1],于是一直错误