- 采药
- 2015-08-15 12:11:08 @
memset(d,0,sizeof(d));
for (int i=1;i<=n;++i) {
for (int j=0;j<=V;++j) {
if (j>=v[i]) d[i][j]=max(d[i-1][j],d[i-1][j-v[i]]+w[i]);
//else d[i][j]=d[i-1][j];
}
}
printf("%d\n",d[n][V]);
我把注释掉的那行恢复过来就能AC,但是注释之后只有40分,求教为什么(ノ ○ Д ○)ノ
3 条评论
-
twd2 LV 9 MOD @ 2015-08-18 02:58:32
要不然d[i][j]就是零了呀!
-
2015-08-17 17:11:18@
好像应该是d[i][j]=max(d[i][j],d[i-1][j-v[i]]+w[i])吧
-
2015-08-15 12:39:19@
完整的
int d[105][1005],n,V,v[105],w[105];
int main() {
memset(d,0,sizeof(d));
scanf("%d%d",&V,&n);
for (int i=1;i<=n;++i) {
scanf("%d%d",&v[i],&w[i]);
}
for (int i=1;i<=n;++i) {
for (int j=0;j<=V;++j) {
if (j>=v[i]) d[i][j]=max(d[i-1][j],d[i-1][j-v[i]]+w[i]);
else d[i][j]=d[i-1][j];
}
}
printf("%d\n",d[n][V]);
return 0;
}
- 1