标签:
二位数组做法;
#include<stdio.h> #include<string.h> #define M 1009 typedef struct pack { int cost; int val; }PACK; int f[M][M];<pre name="code" class="cpp">#include<stdio.h> #include<string.h> #define M 1009 typedef struct pack { int cost; int val; }PACK; int main() { int cas,n,v,i,j; int f[M]; PACK a[M]; scanf("%d",&cas); while(cas--){ scanf("%d%d",&n,&v); memset(f,0,sizeof(f)); for(i=1;i<=n;i++) scanf("%d",&a[i].val); for(i=1;i<=n;i++) scanf("%d",&a[i].cost); for(i=1;i<=n;i++) for(j=v;j>=a[i].cost;j--) if(f[j]<f[j-a[i].cost] + a[i].val) f[j]=f[j-a[i].cost]+a[i].val; printf("%d\n",f[v]); } return 0; }
标签:
原文地址:http://blog.csdn.net/a197p/article/details/46494263