70分求调

P1048 [NOIP2005 普及组] 采药

``` #include <bits/stdc++.h> using namespace std; int dp[110][1010]; int T, m; int t[110]; int v[110]; int main(){ scanf("%d%d", &T, &m); for (int i = 1; i <= m; ++i) { scanf("%d%d", &t[i], &v[i]); } dp[0][0] = 0; for (int i = 1; i <= m; ++i) { dp[i][0] = 0; for (int j = 1; j <= T; ++j) { dp[0][j] = 0; if (t[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - t[i]] + v[i]); } } printf("%d", dp[m][T]); return 0; } ```
by sutiancheng @ 2024-05-03 22:35:23


输入写错了
by sutiancheng @ 2024-05-03 22:35:57


@[sutiancheng](/user/1087520) 已AC,万分感谢
by cao_20115 @ 2024-05-04 17:38:54


|