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

Re:高手帮忙看看,什么bt数据都通过了,但是最后还是wa!

Posted by yyfiby at 2007-04-22 16:32:37 on Problem 1011
In Reply To:高手帮忙看看,什么bt数据都通过了,但是最后还是wa! Posted by:yyfiby at 2007-04-22 16:09:47
> #include <iostream>
> #include <algorithm>
> #include <functional>
> 
> using namespace std;
> 
> int tc;
> int isUsed[64];
> int length[64];
> int pp[64];
> int pp_count[64];
> 
> #define max(a,b) (((a) > (b)) ? (a) : (b))
> 
> bool isOK(int l,int sum,int start,int deep)
> {
> 	if (deep>50)
> 		return false;
> 	for(int i=start;i<tc;i++)
> 	{
> 		if (isUsed[i]==0)
> 			continue;
> 		if (sum+pp[i]==l)
> 		{
> 			isUsed[i]--;	
> 			return true;
> 		}else if(sum+pp[i]<l){		
> 			isUsed[i]--;
> 			if (isOK(l,sum+pp[i],i,deep+1))
> 			{
> 				return true;
> 			}		
> 			isUsed[i]++;
> 		}else if(sum+pp[i]>l){
> 			continue;
> 		}
> 	}
> 
> 	return false;
> }
> 
> 
> 
> void main()
> {
> 	
> 
> 	int i,j;
> 	scanf("%d",&tc);
> 	int maxStick;
> 	int sumStick;
> 	int flag = false;
> 	int start;
> 
> 	while(tc!=0)
> 	{
> 		maxStick = 0;
> 		sumStick = 0;
> 		
> 		for(i=0;i<tc;i++)
> 		{
> 			scanf("%d",&length[i]);
> 			maxStick = max(maxStick,length[i]);
> 			sumStick += length[i];
> 		}
> 		flag = false;
> 	
> 		sort(length,length+tc,greater<int>());
> 		pp[0] = length[0];
> 		pp_count[0] = 1;
> 		j = 0;
> 		for(i=1;i<tc;i++)
> 		{
> 			if(length[i] == pp[j])
> 			{
> 				pp_count[j]++;
> 			}else{
> 				pp[++j] = length[i];
> 				pp_count[j] = 1;
> 			}
> 		}
> 
> 		tc = j + 1;
> 		for(j=maxStick;j<=sumStick;j++)
> 		{
> 			if (sumStick%j!=0)
> 				continue;
> 			if (j==sumStick)
> 			{	
> 				printf("%d\n",j);
> 				break;
> 			}
> 			start = 0;
> 			
> st:			memcpy(isUsed,pp_count,tc*sizeof(int));
> 			flag = isOK(j,0,start,1);
> 			if(!flag)
> 			{				
> 				continue;
> 			}
> 			for(i=0;i<sumStick/j - 2;i++)
> 			{				
> 				flag = isOK(j,0,0,1);
> 				if(!flag)
> 				{				
> 					start++;
> 					goto st;
> 				}
> 			}
> 			
> 			if (flag)
> 			{
> 				printf("%d\n",j);
> 				break;
> 			}
> 		}
> 		
> 		scanf("%d",&tc);
> 	}
> 
> 	return;
> }
> 

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