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 jianzhi at 2011-03-06 00:54:20 on Problem 1014
为什么总是Time Limit Exceeded呢?哪位大虾能帮忙看看呀
#include<iostream>
using namespace std;
int marble[6];
bool half(int d,int n)
{
	if(d==0)
		return true;
	if(n==0)
		return false;
	int i;
	for(i=marble[n-1];i>=0;i--)
	{
		if((d-i*n)>=0)
		{
			marble[n-1]=marble[n-1]-i;
			if(half(d-i*n,n-1))
				return true;
			marble[n-1]=marble[n-1]+i;
		}
	}
	return false;
}

int main()
{
	int sum=0;
	for(int i=0;i<6;i++)
	{
		cin>>marble[i];
		sum=sum+marble[i]*(i+1);
	}
	for(int i=1;sum>0;i++)
	{
		cout<<"Collection #"<<i<<":"<<endl;
		if(half(sum/2,6)&&sum%2==0)
			cout<<"Can be divided."<<endl;
		else
			cout<<"Can't be divided."<<endl;
		sum=0;
		for(int i=0;i<6;i++)
		{
			cin>>marble[i];
			sum=sum+marble[i]*(i+1);
		}
	}
}





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