0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 01:48:56 +00:00
OI-codes/Luogu/P1048/P1048.cpp
2022-01-21 11:27:51 +08:00

25 lines
499 B
C++

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int t, m, v[105], w[105], f[105][105];
int main() {
cin >> t >> m;
for (int i = 1; i <= m; i++) {
cin >> v[i] >> w[i];
}
for (int i = 1; i <= m; i++) {
for (int j = t; j >= 0; j--) {
f[i][j] = f[i - 1][j];
if (j >= v[i]) {
f[i][j] = std::max(f[i][j], f[i - 1][j - v[i]] + w[i]);
}
}
}
cout << f[m][t] << endl;
return 0;
}