背包
背包01
代码块
int dp[1004][1004], v[1004], w[1004];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> v[i] >> w[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
cout << dp[n][m];
return 0;
}