✅
P5662 100pts
This commit is contained in:
parent
2ec168d4be
commit
1bb46a2ec5
@ -26,4 +26,5 @@ add_executable(Playground
|
|||||||
eating-snake/main.cc
|
eating-snake/main.cc
|
||||||
insert-sort/main.cc
|
insert-sort/main.cc
|
||||||
csp-decode/main.cc
|
csp-decode/main.cc
|
||||||
palin/main.cc)
|
palin/main.cc
|
||||||
|
csp-backpack/main.cc)
|
||||||
|
25
csp-backpack/main.cc
Normal file
25
csp-backpack/main.cc
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
#define maxn 10005
|
||||||
|
#define M 105
|
||||||
|
int dp[maxn];
|
||||||
|
int w[M][M];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int T, n, W;
|
||||||
|
cin >> T >> n >> W;
|
||||||
|
for (int i = 1; i <= T; i++)
|
||||||
|
for (int j = 1; j <= n; j++) // <- used to be i++
|
||||||
|
cin >> w[i][j];
|
||||||
|
for (int i = 1; i < T; i++) {
|
||||||
|
memset(dp, 0, sizeof dp);
|
||||||
|
for (int j = 1; j <= n; j++)
|
||||||
|
for (int k = w[i][j]; k <= W; k++)
|
||||||
|
dp[k] = max(dp[k], dp[k - w[i][j]] + w[i + 1][j] - w[i][j]);
|
||||||
|
W = max(dp[W] + W, W);
|
||||||
|
}
|
||||||
|
cout << W << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user