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

help!!why tle??

Posted by shenfangyi at 2007-01-20 20:07:08 on Problem 1011
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[70],s[70],m,t,n;
bool dfs(int x,int y,int max)
{
	if(x<0)return true;
	int i=0;
	if(x<n-1&&s[x]==s[x+1])i=y-1;
	for(;i<=max&&i<t/m;i++)if(a[i]+s[x]<=m)
	{
		a[i]+=s[x];
		if(dfs(x-1,i+1,(i+1>max)?i+1:max))return true;
		a[i]-=s[x];
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	while(n)
	{
		t=0;
		for(int i=0;i<n;i++)scanf("%d",s+i),t+=s[i];
		sort(s,s+n);
		for(m=s[n-1];m<t;m++)if(t%m==0)
		{
			memset(a,0,sizeof(a));
			if(dfs(n-1,0,0))break;
		}
		printf("%d\n",m);
		scanf("%d",&n);
	}
}

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