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

为什么老WA?求教

Posted by 888899977 at 2007-09-08 00:21:52 on Problem 1014
#include <iostream>
using namespace std;
bool ans[500];int i=0;
int M[6];
bool search(int len,int rest)
{
    if(len<1) return false;
    if(rest%len==0&&rest/len<=M[len-1]) return true;
    else
    {
        rest-=len*min(rest/len,M[len-1]);
        if(search(len-1,rest))  return true;
        else
            for(int j=1;j<min(rest/len,M[len-1]);++j)
                if(search(len,rest+j*len))  return true;
    }
    return false;
}    
bool judge()
{
    int all=M[0]+2*M[1]+3*M[2]+4*M[3]+5*M[4]+6*M[5];
    if(all%2) return false;
    else return search(6,all/2);
}
int main()
{
    cin>>M[0]>>M[1]>>M[2]>>M[3]>>M[4]>>M[5];
    while(M[0]|M[1]|M[2]|M[3]|M[4]|M[5])
    {
        ans[i++]=judge();
        cin>>M[0]>>M[1]>>M[2]>>M[3]>>M[4]>>M[5];
    }
    for(int j=0;j<i;++j)
    {
        printf("Collection #%d:\n",j+1);
        printf(ans[j]?"Can be divided.":"Can't be divided.");
        cout<<endl<<endl;
    }    
    system("pause");
    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