lanqiao 1175 小明的背包2(完全背包)

This commit is contained in:
2025-04-09 14:04:35 +08:00
parent cb4b4332b8
commit 8fff611054

View File

@@ -0,0 +1,19 @@
// lanqiao 1175 小明的背包2(完全背包)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int dp[N];
int main()
{
// 请在此输入您的代码
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m; cin >> n >> m;
for(int i = 1; i <= n; i++){
int w, v; cin >> w >> v;
for(int j = w; j <= m; j++){
dp[j] = max(dp[j], dp[j-w] + v);
}
}
cout << dp[m] << '\n';
return 0;
}