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

哪位大神告诉下这题该怎么剪枝,本人小白一直TLE

Posted by pheonix2012 at 2012-07-23 00:37:05 on Problem 1014
#include<iostream>
using namespace std;
int a,b,c,d,e,f,i,num=1,sum;
int number[6],vaule[20001];
bool dfs(int now,int n)
{if(now==sum-now) return true;
else if(now<sum-now)
{for(int k=n;k<i;k++)
if(dfs(now+vaule[k],k+1)) return true;}
return false;}
int main()
{while(cin>>a>>b>>c>>d>>e>>f)
{if(a||b||c||d||e||f)
{number[0]=a;
number[1]=b;
number[2]=c;
number[3]=d;
number[4]=e;
number[5]=f;
sum=0;
for(i=0;i<6;i++)
	sum+=number[i]*(i+1);
memset(vaule,-1,sizeof(vaule));
for(i=0;i<a;i++)
	vaule[i]=1;
while(b--)
	{vaule[i]=2;i++;}
while(c--)
	{vaule[i]=3;i++;}
while(d--)
    {vaule[i]=4;i++;}
while(e--)
    {vaule[i]=5;i++;}
while(f--)
    {vaule[i]=6;i++;}
if(sum%2==0)
{if(dfs(0,0))
cout<<"Collection #"<<num<<":\n"<<"Can be divided.\n";
else
	cout<<"Collection #"<<num<<":\n"<<"Can't be divided.\n";
}
else
    cout<<"Collection #"<<num<<":\n"<<"Can't be divided.\n";
    num++;}
else break;}
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