Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re o(N*V)算法 什么牛逼数据都过了 但交不上In Reply To:多重背包,怎么老是RE,无语了,看看 Posted by:dynamic_study at 2009-08-06 20:44:00 #include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ int n,c; int f[100001],v[101],mm[100001],m[101]; while(scanf("%d%d",&n,&c)){ if(n==0&&c==0) break; for(int i=1;i<=n;i++) scanf("%d",&v[i]); for(int i=1;i<=n;i++) scanf("%d",&m[i]); for(int i=1;i<=c;i++) f[i] = 0; f[0] = 1; for(int i=1;i<=n;i++){ memset(mm,0,sizeof(mm)); for(int j=v[i];j<=c && mm[j-v[i]]<m[i];j++){ if(f[j]==0 && f[j-v[i]]==1){ f[j] = 1; mm[j] = mm[j-v[i]]+1; } } } int count = 0; for(int i=1;i<=c;i++) if(f[i]==1) count++; printf("%d\n",count); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator