为啥样例输出0呀

P1048 [NOIP2005 普及组] 采药

@[Michelle01](/user/957640) 你这外层循环从0到m-1的,内层循环也是从0到t-1的,最后输出dp[m-1][t-1]、就好了
by hash_peas @ 2023-07-29 15:34:11


@[xxx666xxx](/user/774876) 噢,明白了,算QQ
by Michelle01 @ 2023-07-29 15:34:48


@[xxx666xxx](/user/774876) ~~cao~~,用手机打就是难受
by hash_peas @ 2023-07-29 15:35:13


@[xxx666xxx](/user/774876) 咦?他说编译失败
by Michelle01 @ 2023-07-29 15:35:48


@[Michelle01](/user/957640) 等会,我用电脑查看一下
by hash_peas @ 2023-07-29 15:40:58


@[Michelle01](/user/957640) 别取time这个名字好像就通过编译了 code ``` #include <stdio.h> #include<algorithm> #include<math.h> #include<iostream> using namespace std; int dp[101][101]; int ti[101]; int mo[101]; int main() { int t, m; cin >> t >> m; for (int i = 1; i <= m; i++) { cin >> ti[i] >> mo[i]; } for (int i = 1; i <= m; i++) { for (int j = 1; j <= t; j++) { if (j < mo[i]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - ti[i]] + mo[i]); } } } cout << dp[m][t]; return 0; } ```
by hash_peas @ 2023-07-29 15:55:23


@[Michelle01](/user/957640) 以1开始最好,不用考虑那么多情况
by hash_peas @ 2023-07-29 15:56:33


@[xxx666xxx](/user/774876) 还是不行,我提交了之后20分
by Michelle01 @ 2023-07-29 22:19:36


@[Michelle01](/user/957640) 改了一下,能AC了 ``` #include <stdio.h> #include<algorithm> #include<math.h> #include<iostream> using namespace std; int dp[1001][1001]; int ti[1001]; int mo[1001]; int main() { int t, m; cin >> t >> m; for (int i = 1; i <= m; i++) { cin >> ti[i] >> mo[i]; } for (int i = 1; i <= m; i++) { for (int j = 1; j <= t; j++) { if (j < ti[i]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - ti[i]] + mo[i]); } } } cout << dp[m][t]; return 0; } ```
by hash_peas @ 2023-07-29 22:31:23


@[xxx666xxx](/user/774876) 欧克欧克,我太粗心了没看到那个问题(菜
by Michelle01 @ 2023-07-29 22:32:12


|