| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:这个题怎么剪枝呀 怎样去掉那些重复的状态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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator