求大佬告知哪儿错了 50分 好气啊……

P1048 [NOIP2005 普及组] 采药

```cpp #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <bits/stdc++.h> using namespace std; int f[1005][1005],w[105],v[105]; int main(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); int t,n; scanf("%d%d",&t,&n); for(int i=1;i<=n;i++){ scanf("%d%d",&w[i],&v[i]); } for(int i=1;i<=n;i++){ for(int j=t;j>=0;j--){ if(j>=w[i]){ f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]); } else { f[i][j]=f[i-1][j]; } } } printf("%d",f[n][t]); return 0; } ```
by mjc24268 @ 2018-11-07 00:11:13


你数组开小了,注意,你f数组里第一维是n,第二维是你的T,T的上限是1000
by mjc24268 @ 2018-11-07 00:12:07


@[mjc24268](/space/show?uid=112675) 哦哦 好的 谢谢AC辣
by 慕柒宝宝啊丿 @ 2018-11-07 23:19:43


1.max函数可能有问题 2.你自己看看变量名错没错
by huangsiyue @ 2019-01-25 21:01:57


|