0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 17:51:58 +00:00

P1060 开心的金明

R40518321
This commit is contained in:
Baoshuo Ren 2020-10-25 20:15:21 +08:00 committed by Baoshuo Ren
parent 4df21c738a
commit 19ff441b6e
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

25
problem/P1060/P1060.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, v[30005], w[30005], f[30][30005];
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> v[i] >> w[i];
w[i] *= v[i];
}
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (j >= v[i]) {
f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]);
}
else {
f[i][j] = f[i - 1][j];
}
}
}
cout << f[m][n] << endl;
return 0;
}