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 |
我可爱的母函数,结果超了#include<iostream> using namespace std; int main() { int i,j; int c1[10000],c2[10000]; int money,n,m,a[101],num[101],ans; while(cin>>n>>m&&n||m) { for(i=0;i<n;i++) cin>>a[i]; money=0; for(i=0;i<n;i++) { cin>>num[i]; money+=num[i]*a[i]; } for(i=0;i<=money;i++) { c1[i]=0;c2[i]=0; } for(i=0;i<n;i++) { if(i==0) { for(j=0;j<=num[0];j++) c1[j]=1; } else { for(j=0;j<=money;j++) for(int k=0;(k+j)<=money&&k<=a[i]*num[i];k+=a[i]) c2[k+j]+=c1[j]; for(j=0;j<=money;j++) { c1[j]=c2[j];c2[j]=0; } } } ans=0; for(i=1;i<=m&&i<=money;i++) { if(c1[i]!=0) ans++; } cout<<ans<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator