Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我可爱的母函数,结果超了

Posted by dynamic_study at 2009-08-05 19:44:38 on Problem 1742 and last updated at 2009-08-05 19:47:45
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator