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 6754228 at 2007-12-07 21:08:01 on Problem 1014
#include"stdio.h"

int a[6];

inline int min(int x,int y)
{
	return x<y?x:y;
}

bool f(int j, int b)
{  
	if( j ==-1 )
		return false;
	int k=a[j], p=b;

	while(k!=0)
	{
		p-=j+1;
		if(p==0)
			return true;
		k--;
	}
	p=j+1;
	for( k=p * min(a[j], b/p); k>=0; k-=p)
		if( f(j - 1, b - k ) )
			return true;
    return false;
}

int main()
{
	int t;
	int i1 = 0;
    
    while(++i1)
	{
	  t = 0;
	  scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]);
	  t = a[0]*1+a[1]*2+a[2]*3+a[3]*4+a[4]*5+a[5]*6;
	  if( t == 0 )
		  break;
	  if( t & 1)
      {   
		 printf("Collection #%d:\nCan't be divided.\n\n",i1);
	      continue;
      }
	  if( f( 5 , t/2 ) )
	     printf("Collection #%d:\nCan be divided. \n\n",i1);
	  else 
		 printf("Collection #%d:\nCan't be divided.\n\n",i1);

	}
	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