0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-27 06:31:57 +00:00
OI-codes/Luogu/P1048/P1048.cpp

25 lines
499 B
C++
Raw Normal View History

#include <iostream>
2020-10-17 14:10:55 +00:00
using std::cin;
using std::cout;
using std::endl;
int t, m, v[105], w[105], f[105][105];
2020-10-17 14:10:55 +00:00
int main() {
cin >> t >> m;
for (int i = 1; i <= m; i++) {
cin >> v[i] >> w[i];
2020-10-17 14:10:55 +00:00
}
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]);
2020-10-17 14:10:55 +00:00
}
}
}
cout << f[m][t] << endl;
2020-10-17 14:10:55 +00:00
return 0;
}