半年过去了,当时比完赛心态炸了,一点也不想看这场的题了,
最近想搞搞DP, 于是才补了这题……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <bits/stdc++.h> using namespace std; typedef long long ll;
const int N = 1010;
ll dp[N][N]; int n, h, s; struct node { ll h, s, w; }a[N];
int main() { cin >> n >> h >> s; for(int i = 1; i <= n; i++) { cin >> a[i].h >> a[i].s >> a[i].w; } for(int i = 1; i <= n; i++) { for(int j = h; j > a[i].h; j--) { for(int k = s; k >= 0; k--) { if(j + k > a[i].s + a[i].h) { if(k >= a[i].s) dp[j][k] = max(dp[j][k], dp[j-a[i].h][k-a[i].s] + a[i].w); else dp[j][k] = max(dp[j][k], dp[j-a[i].h-(a[i].s-k)][0] + a[i].w); } } } } cout << dp[h][s] << endl; return 0; }
|