Files
lanqiao/00lanqiao chap/test100-1-4.cpp

19 lines
443 B
C++

// 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++){ // j >= w
dp[j] = max(dp[j], dp[j-w] + v);
}
}
cout << dp[m] << '\n';
return 0;
}