题目描述
思路
代码
#include <cstdio>
#define max(a, b) (a) > (b) ? a : b
int ans[1005][1005];
int n, v, tj[1005], val[1005];
int main() {
scanf("%d %d", &n, &v);
for (int i = 1; i <= n; ++i) scanf("%d %d", &tj[i], &val[i]);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= v; ++j) {
if (j >= tj[i]) ans[i][j] = max(ans[i - 1][j - tj[i]] + val[i], ans[i - 1][j]);
else ans[i][j] = ans[i - 1][j];
}
}
printf("%d
", ans[n][v]);
return 0;
}