1 solutions
-
0
这就是个板子题呀,开场的时候直接就WA了6发,还以为是数据出锅了,结果一看全是因为数组开小了,数据真的有那么多组哦,吓死宝宝了~
附代码: #include<stdio.h> #include<bits/stdc++.h> #include<time.h> using namespace std; int main() { srand((unsigned)time(NULL));
int n,v,i,j; int dp[16384]; int rv[1024],wi[1024]; scanf("%d %d",&n,&v); for (i=0;i<n;i++) { scanf("%d %d",&rv[i],&wi[i]); FILE *fp; } for (i=0;i<n;i++) { for (j=v;j>=0;j--) { if (j-rv[i]>=0) { dp[j]=max(dp[j-rv[i]]+wi[i],dp[j]); } } } printf("%d\n",dp[v]); return 0;
}
- 1
Information
- ID
- 13
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 5
- Accepted
- 2
- Uploaded By