lanqiao 1174 小明的背包1(降维优化)
This commit is contained in:
28
00lanqiao chap/test100-1-2.cpp
Normal file
28
00lanqiao chap/test100-1-2.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// 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[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 = V; j >= w; j--){
|
||||||
|
dp[j] = max(dp[j], dp[j-w] + v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << dp[V] << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* test samples -> 37
|
||||||
|
5 20
|
||||||
|
1 6
|
||||||
|
2 5
|
||||||
|
3 8
|
||||||
|
5 15
|
||||||
|
3 3
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user