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 speedcell4 at 2011-10-17 09:38:38 on Problem 1014
#include<iostream>

using namespace std;

const int MAXN = 1000012;
int times=1,a[6],dp[MAXN];

void Zero_One(int c,int v)
{
    for(int i=v;i>=c;i--) if(dp[i-c]) dp[i]=true;
}
void Complete(int c,int v)
{
    for(int i=c;v>=i;i++) if(dp[i-c]) dp[i]=true;
}
void Multiple(int c,int v,int n)
{
    if(c*n>=v) Complete(c,v);
    else
    {
        for(int i=1;i<n;i*=2)
        {
            n-=i;
            Zero_One(i*c,v);
        }
        if(n) Zero_One(n*c,v);
    }
}
int main()
{
    while(scanf("%d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]),a[0]||a[1]||a[2]||a[3]||a[4]||a[5])
    {
        int v=0;
        memset(dp,0,sizeof(dp)); dp[0]=true;
        for(int i=0;6-i>0;i++) v+=((i+1)*a[i]);
        for(int i=0;6-i>0;i++) Multiple(i+1,v,a[i]);
        printf("Collection #%d:\n",times++);
        if(v%2==1) printf("Can't be divided.\n");
        else
        {
            if(!dp[v/2]) printf("Can't be divided.\n");
            else printf("Can be divided.\n");
        }
        printf("\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