zju1149

#include<iostream>

using namespace std;

#define size 6

 

typedef struct node{

       int num;

       int value;

       int amount;

}node;

 

node marble[size+1];

 

int total_value[size+1];

 

 

int cmp(const void*a,const void*b)

{

       node *temp1=(node *)a;

       node *temp2=(node *)b;

       return ( temp1->amount - temp2->amount ) ;

}

 

inline int min(int a,int b)

{ if(a<=b) return a; else return b; }

 

bool dp[size+1][122];

 

 

 

 

void init()

{

       int i,half,j,k;

       int temp,temp1;

       if(marble[1].num%2==0 && marble[2].num%2==0 && marble[3].num%2==0 && marble[4].num%2==0 && marble[5].num%2==0 && marble[6].num%2==0)

       {

              cout<<"Can be divided."<<endl;

              return ;

       }

 

 

       if(marble[6].num>5)  marble[6].num=marble[6].num%2 + 4;

       if(marble[5].num>6)  marble[5].num=6 - marble[5].num%2;

       if(marble[4].num>5)  marble[4].num=marble[4].num%2 + 4;

       if(marble[3].num>5)  marble[3].num=marble[3].num%2 + 4;

       if(marble[2].num>4)  marble[2].num=4 - marble[2].num%2;

       if(marble[1].num>6)  marble[1].num=6 - marble[1].num%2;

 

       for(i=1;i<=6;i++)

       {

               marble[i].amount=marble[i].num * marble[i].value;

       }

 

    qsort(&marble[1],size,sizeof(marble[1]),cmp);

       total_value[0]=0;

       for(i=1;i<=6;i++)

              total_value[i]=total_value[i-1]+marble[i].amount;

       if(total_value[6]%2==1)

       {

              cout<<"Can't be divided."<<endl;

              return;

       }

       //初始化第一行

       half=total_value[6]/2;

       for(j=1;j<=half;j++)

              if( j/marble[1].value<=marble[i].num &&  j%marble[1].value==0)

                     dp[1][j]=true;

              else dp[1][j]=false;

       for(i=1;i<=6;i++) dp[i][0]=true;

 

       for(i=2;i<=6;i++)

       {

              temp=min(total_value[i],half);

              for(j=1;j<=temp;j++)

              {

                     dp[i][j]=false;

                     temp1=min(marble[i].num,j/marble[i].value);

 

                     for(k=0;k<=temp1;k++)

                            if(dp[i-1][j-k*marble[i].value]==true)

                            {

                                   dp[i][j]=true;

                                   break;

                            }

                    

              }

              for(j=temp+1;j<=half;j++)

              {

                     dp[i][j]=false;

              }

       }

 

       if(dp[6][half])

       {

              cout<<"Can be divided."<<endl;

              return ;

       }

       else

       {

              cout<<"Can't be divided."<<endl;

              return;

       }

}

 

 

int main()

{

       int i;

       int test=1;

       while(1)

       {

       for(i=1;i<=6;i++)

       {

              cin>>marble[i].num;   marble[i].value=i;

       }

       if(marble[1].num==0 && marble[2].num==0 && marble[3].num==0 && marble[4].num==0 && marble[5].num==0 && marble[6].num==0)

              break;

       cout<<"Collection #"<<test++<<':'<<endl;

       init();

       cout<<endl;

       }

       return 0;

}

 

 

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值