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 guowangguilai at 2008-08-10 21:47:39 on Problem 1275
方法不对头?


#include<iostream.h>


int nt,n,r[24],t[1001];
int num,tt,max=99999;
int fun(int,int);
int main()
{
	int i,s=0;
	cin>>nt;
	while(nt--)
	{
		num=0;
		for(i=0;i<24;i++)
			{scanf("%d",r+i);if(r[i]>0)s++;}
		cin>>n;
		for(i=0;i<n;i++)
			scanf("%d",t+i);
		tt=fun(0,s);
		if(tt==max)printf("No Solution\n");
		else printf("%d\n",tt);
		
	}
	return 0;
}
int fun(int k,int s)
{
	
	int c,x,y,i;
	if(s<=0)return 0;
	if(k>n-1)
	{
		
		if(!s)return 0;
		else return max;
	}
		if(s>=n-k)x=max;
		else	x=fun(k+1,s);
	
		for(i=t[k];i<=t[k]+7;i++)
	{	
		c=i%24;
		r[c]--;
		if(r[c]==0)s--;
	}
	
	y=fun(k+1,s)+1;
	for(i=t[k];i<=t[k]+7;i++)
	{	c=i%24;
		r[c]++;
		if(r[c]==1)s++;
	}
	return x<y?x:y;
	
	
	
}	
	
		


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