0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 10:25:24 +00:00
OI-codes/problem/P1048/P1048.cpp
2020-10-17 22:10:55 +08:00

22 lines
484 B
C++

#include <bits/stdc++.h>
using namespace std;
int main() {
int t, m, w[1005], v[1005], dp[1005][1005];
cin >> t >> m;
for (int i = 1; i <= m; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= m; i++) {
for (int j = t; j >= 0; j--) {
dp[i][j] = dp[i - 1][j];
if (j >= w[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
}
cout << dp[m][t] << endl;
return 0;
}