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