29 lines
539 B
C++
29 lines
539 B
C++
// lanqiao 1174 小明的背包1
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
#define endl '\n'
|
|
const int N = 1e2+10, M = 1e3 + 10;
|
|
int dp[N][M];
|
|
signed main()
|
|
{
|
|
// 请在此输入您的代码
|
|
int n, V; cin >> n >> V;
|
|
for(int i = 1; i <= n; i++){
|
|
int w, v; cin >> w >> v;
|
|
for(int j = 0; j <= V; j++){
|
|
if(j >= w) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v);
|
|
else dp[i][j] = dp[i-1][j];
|
|
}
|
|
}
|
|
cout << dp[n][V] << endl;
|
|
return 0;
|
|
}
|
|
/* test samples -> 37
|
|
5 20
|
|
1 6
|
|
2 5
|
|
3 8
|
|
5 15
|
|
3 3
|
|
*/ |