1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <iostream> using namespace std; int T, M; int t[101], v[101]; int dp[101][1001]; int main() { cin >> T >> M; for (int i = 1; i <= M; ++i) cin >> t[i] >> v[i]; for (int i = 1; i <= M; ++i) for (int j = 0; j <= T; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= t[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - t[i]] + v[i]); } cout << dp[M][T] << endl; return 0; }
|