1 solutions
-
0
就01背包模板,数据简单。
#include<stdio.h> int max(int a,int b) { if (a>b) return a; else return b; } int main() { int f[1000]={0},c[1000],w[1000]; int n,v,i,j; scanf("%d%d",&n,&v); for(i=1;i<=n;i++)scanf("%d%d",&c[i],&w[i]); for(i=1;i<=n;i++) for(j=v;j>=c[i];j--) { f[j]=max(f[j],f[j-c[i]]+w[i]); } printf("%d ",f[v]); return 0; }
- 1
Information
- ID
- 20
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 6
- Accepted
- 5
- Uploaded By