这两种写法前者100后者80,为什么

P1048 [NOIP2005 普及组] 采药

**第二个错了重发** ```cpp //80 #include <iostream> #include <cmath> using namespace std; int main() { int t,v,w,j,m,i,f[1000]={0}; cin>>t>>m; for(i=1;i<=m;i++) { cin>>v>>w; for(j=t;j>=v;j--) { f[j]=max(f[j-v]+w,f[j]); } } cout<<f[t]<<endl; return 0; } ```
by 匿名用户ㅤ @ 2018-10-20 14:58:58


下标居然有变负的危险诶
by touristX @ 2018-10-20 14:59:28


哦后面发的下标没事
by touristX @ 2018-10-20 14:59:59


不可能的吧
by Trimsteanima @ 2018-10-20 15:00:06


你确定后面这种写法有80?
by Trimsteanima @ 2018-10-20 15:01:13


你这个第一个能过也是奇葩,数组不够,当t= 1000时,你的数组并不能访问到f[1000]
by moye到碗里来 @ 2018-10-20 15:11:59


@[匿名用户ㅤ](/space/show?uid=84806)
by moye到碗里来 @ 2018-10-20 15:13:18


@[moye到碗里来](/space/show?uid=52576) 我意识到不够了不过过了懒得改了
by 匿名用户ㅤ @ 2018-10-20 15:14:59


@[匿名用户ㅤ](/space/show?uid=84806) 你第二个的问题也是这个,把1000改成1005就能过
by moye到碗里来 @ 2018-10-20 15:15:42


|