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:刚刚试用dfs可以0ms!个人分享,请不要喷!

Posted by huangchang9001 at 2011-03-26 19:28:58 on Problem 3628
In Reply To:刚刚试用dfs可以0ms!个人分享,请不要喷! Posted by:huangchang9001 at 2011-03-26 19:24:01
> 刚开始和大家一样16ms,但是看到有人有0ms通过,就想试下能不能搜索条件!
> 最后发现当差值为0时可以停止下面的搜索!0是最小的差值,如果存在0就没必要在搜索!
> 代码如下:
> #define max 2147483647
>int dfs(int min,int i)
{
	int x,y;
	if(i==0) 
	{
		if(H[i]>=min)
	     	return H[i]-min;
		else
			return max;
	}
	if(H[i]==min)
		return 0;
	if(H[i]<min)
	{
		x=dfs(min-H[i],i-1);
		if(x==0)
			return 0;
	    y=dfs(min,i-1);
	}
	else 
	{
		x=dfs(min,i-1);
		y=H[i]-min;
	}
  	if(x>y)
	  	return y;
	else 
	   	return x;
}

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