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 cjrzh at 2013-03-07 15:56:38 on Problem 1014
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
    int N;
    int a[800],b[800];
    int SUM;
    int x[7];
    int cas=0;
    while(cin>>x[1]>>x[2]>>x[3]>>x[4]>>x[5]>>x[6])
    {
    	cas++;
        SUM=0;
        for(int i=1;i<=6;i++)
        {
        	if(x[i]>61)
        	{
        		if(x[i]%2)x[i]=61;
        		else x[i]=60;
        	}
        	SUM+=x[i]*i;
        }
        if(SUM==0)break;
        if(SUM%2)
        {
        	cout<<"Collection #"<<cas<<":\n"<<"Can't be divided.\n\n";
        	continue;
        }
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        a[0]=1;
        N=SUM/2;
        for(int i=1;i<=6;i++)
        {
        	if(x[i]==0)continue;
            for(int j=0;j<=N;j++)
                for(int k=0;k<=x[i]&&k*i+j<=N;k++)
                    b[k*i+j]+=a[j];
            for(int j=0;j<=N;j++)
            {
                a[j]=b[j];
                b[j]=0;
            }

        }
        if(a[N]>0)cout<<"Collection #"<<cas<<":\n"<<"Can be divided.\n\n";
        else cout<<"Collection #"<<cas<<":\n"<<"Can't be divided.\n\n";
    }
    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