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 wolai at 2012-09-06 00:14:50 on Problem 1014
#include <iostream>
 using namespace std;
 int n[7];
 bool flag;

 void dfs(int des)
 {
     if(des==0)
     {
         flag=true;
         return;
     }

     for(int i=6;i>0;i--)
     {
         if(des>=i && n[i]>0)
         {
             n[i]--;
             dfs(des-i);
             if(flag)
                 return;
         }
     }
 }

 int main()
 {
     int count=1;
     while(cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4] >> n[5])
     {
         int sum=0;
         for(int i=1;i<=6;i++)
             sum+=(i+1)*n[i];

         if(sum==0)
             break;

         if(sum%2==1)
         {
             cout << "Collection #" << count << ":\n" << "Can't be divided.\n\n";
             count++;
         }
         else
         {
             int des=sum/2;
             flag=false;
             dfs(des);

             if(flag)
                 cout << "Collection #" << count << ":\n" << "Can be divided.\n\n";
             else
                 cout << "Collection #" << count << ":\n" << "Can't be divided.\n\n";
             count++;
         }
     }
 }

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