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:这个题怎么剪枝呀 怎样去掉那些重复的状态

Posted by xiaomi at 2004-03-26 01:11:11 on Problem 1011
In Reply To:这个题怎么剪枝呀 怎样去掉那些重复的状态 Posted by:wanglei at 2004-03-25 23:58:44
int search(int p,int now,int next) //加了一个next,前面的可以不检验了
{
	int i;
	if (flag) return 0;
	if (p==total && now==len){ 
		flag=1;
		return 0;
	}
	if (now==len){
	       	p++;
		now=0;
	}
         if (stick[next]==0) return 0; //剪枝1
         if (used[next-2]==0&&stick[next-2]==stick[next-1]) return 0; //剪枝2,可以过uva变态数据
	for(i=next;i<=n;i++){  
		if (used[i]==0 && (now+stick[i])<=len) {
			used[i]=1;
			if (!flag) search(p,now+stick[i],i+1); 
			used[i]=0;
                           if (flag) return 0; //剪枝3
                           if (stick[i]==now) return 0; //强剪枝,能过poj
		}
	}
	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