You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
464 B
20 lines
464 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 1010;
|
|
int n, m;
|
|
int f[N][N];
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) {
|
|
int v, w;
|
|
cin >> v >> w;
|
|
for (int j = 1; j <= m; j++) {
|
|
f[i][j] = f[i - 1][j];
|
|
if (j >= v)
|
|
f[i][j] = max(f[i][j], f[i - 1][j - v] + w); // 两种情况取最大值
|
|
}
|
|
}
|
|
|
|
printf("%d\n", f[n][m]);
|
|
return 0;
|
|
} |