0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

1290. 采药

http://ybt.ssoier.cn:8088/statusx.php?runidx=15594277
This commit is contained in:
Baoshuo Ren 2022-04-03 21:49:32 +08:00
parent a1193e508a
commit 787d25df06
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

28
ybt/1290/1290.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
int m, n, w[N], v[N], f[N];
int main() {
std::ios::sync_with_stdio(false);
cin >> m >> n;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = m; j; j--) {
f[j] = std::max(f[j], j >= w[i] ? f[j - w[i]] + v[i] : f[j]);
}
}
cout << f[m] << endl;
return 0;
}