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 justdo at 2009-03-09 15:16:06 on Problem 1011
#include<cstdio>
#include<cstdlib>

int stick[64];
bool flag[64];
int n;

int cmp(const void *a,const void *b)
{
	return *(int *)b-*(int *)a;
}

bool isok(int sum,int i,int row)
{
	if(row==0)
		return false;

	flag[i]=true;

	if(sum-stick[i]==0)
		return true;

	if(sum-stick[i]>0)
	{
		for(int j=i+1;j<n;j++)
			if(!flag[j]&&isok(sum-stick[i],j,row-1))
				return true;
	}
	flag[i]=false;
	return false;
}

int main()
{
	int i,max,sum,row;
	while(scanf("%d",&n),n!=0)
	{
		max=0;
		sum=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",stick+i);
			flag[i]=false;
			if(stick[i]>max)
				max=stick[i];
			sum+=stick[i];
		}
		qsort(stick,n,sizeof(int),cmp);
		
		while(1)
		{
			
			if(sum%max==0)
			{
				row=max;
				for(i=0;i<n;i++)
					if(!flag[i]&&!isok(max,i,row))
						break;
				if(i==n)
					break;
			}
			max++;
			for(i=0;i<n;i++)
				flag[i]=false;
		}
		printf("%d\n",max);
	}
	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