mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:31:59 +00:00
P1048 采药
R39995473
This commit is contained in:
parent
c6e7e720fa
commit
41988fc322
21
problem/P1048/P1048.cpp
Normal file
21
problem/P1048/P1048.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int t, m, w[1005], v[1005], dp[1005][1005];
|
||||
cin >> t >> m;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> w[i] >> v[i];
|
||||
}
|
||||
for (int i = 1; i <= m; i++) {
|
||||
for (int j = t; j >= 0; j--) {
|
||||
dp[i][j] = dp[i - 1][j];
|
||||
if (j >= w[i]) {
|
||||
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << dp[m][t] << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user