0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-05 13:38:47 +00:00
OI-codes/Luogu/P1060/P1060.cpp

25 lines
526 B
C++
Raw Normal View History

2020-10-25 12:15:21 +00:00
#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]);
2021-11-19 09:01:13 +00:00
} else {
2020-10-25 12:15:21 +00:00
f[i][j] = f[i - 1][j];
}
}
}
cout << f[m][n] << endl;
return 0;
}