欢迎来到天天文库
浏览记录
ID:21981757
大小:343.00 KB
页数:53页
时间:2018-10-18
《acm国际大学生程序设计竞赛系列讲座-通用搜索算法及实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ACM国际大学生程序设计竞赛系列讲座--------------通用搜索算法及实现目录1.组合问题的通用搜索算法1.1状态空间树的搜索1.2状态空间的原地搜索和展开搜索1.3基于遍历器的搜索2.优化问题的通用搜索算法2.1加权状态空间树的搜索2.2加权状态空间的原地搜索和展开搜索状态空间树的搜索publicinterfaceNode{intsubnodenum();booleantarget();Nodedown(inti);voidoutput(booleancn);}publicinterfaceMonoextendsNode{Nodeup();}publicclass
2、Backtracking{Monoprob;intnum,bound,dep,level;publicBacktracking(Monop,intb,intd){prob=p;bound=b;dep=d;}publicvoiddepthfirst(){intn=prob.subnodenum();if(prob.target()){prob.output(true);++num;}for(inti=0;num3、ens1implementsMono{intn,level;int[]board;PrintWriterout;boolean[]column,d1,d2;publicQueens1(intk,PrintWritero){n=k;board=newint[n];out=o;column=newboolean[n];d1=newboolean[2*n-1];d2=newboolean[2*n-1];}publicNodedown(inti){Queens1ans=null;if(level4、1]){column[i]=d1[level+i]=d2[level-i+n-1]=true;board[level++]=i;ans=this;}returnans;}publicNodeup(){inti=board[--level];column[i]=d1[level+i]=d2[level-i+n-1]=false;returnthis;}publicintsubnodenum(){returnlevel5、no{intn,level;int[]board;PrintWriterout;publicQueens(intk,PrintWritero){n=k;board=newint[n];out=o;}publicNodedown(inti){Queensans=null;booleannorm=level=0;--k)norm=i!=board[k]&&i+level-k!=board[k]&&i-level+k!=board[k];if(norm){board[level++]=i;ans=this;}returnan6、s;}publicNodeup(){--level;returnthis;}publicintsubnodenum(){returnlevel7、ublicintsubnodenum(){returnlevel=level8、9、perm[k]!=i;}if(ans){perm[level++]=i;returnthis;}elsereturnnull;
3、ens1implementsMono{intn,level;int[]board;PrintWriterout;boolean[]column,d1,d2;publicQueens1(intk,PrintWritero){n=k;board=newint[n];out=o;column=newboolean[n];d1=newboolean[2*n-1];d2=newboolean[2*n-1];}publicNodedown(inti){Queens1ans=null;if(level4、1]){column[i]=d1[level+i]=d2[level-i+n-1]=true;board[level++]=i;ans=this;}returnans;}publicNodeup(){inti=board[--level];column[i]=d1[level+i]=d2[level-i+n-1]=false;returnthis;}publicintsubnodenum(){returnlevel5、no{intn,level;int[]board;PrintWriterout;publicQueens(intk,PrintWritero){n=k;board=newint[n];out=o;}publicNodedown(inti){Queensans=null;booleannorm=level=0;--k)norm=i!=board[k]&&i+level-k!=board[k]&&i-level+k!=board[k];if(norm){board[level++]=i;ans=this;}returnan6、s;}publicNodeup(){--level;returnthis;}publicintsubnodenum(){returnlevel7、ublicintsubnodenum(){returnlevel=level8、9、perm[k]!=i;}if(ans){perm[level++]=i;returnthis;}elsereturnnull;
4、1]){column[i]=d1[level+i]=d2[level-i+n-1]=true;board[level++]=i;ans=this;}returnans;}publicNodeup(){inti=board[--level];column[i]=d1[level+i]=d2[level-i+n-1]=false;returnthis;}publicintsubnodenum(){returnlevel5、no{intn,level;int[]board;PrintWriterout;publicQueens(intk,PrintWritero){n=k;board=newint[n];out=o;}publicNodedown(inti){Queensans=null;booleannorm=level=0;--k)norm=i!=board[k]&&i+level-k!=board[k]&&i-level+k!=board[k];if(norm){board[level++]=i;ans=this;}returnan6、s;}publicNodeup(){--level;returnthis;}publicintsubnodenum(){returnlevel7、ublicintsubnodenum(){returnlevel=level8、9、perm[k]!=i;}if(ans){perm[level++]=i;returnthis;}elsereturnnull;
5、no{intn,level;int[]board;PrintWriterout;publicQueens(intk,PrintWritero){n=k;board=newint[n];out=o;}publicNodedown(inti){Queensans=null;booleannorm=level=0;--k)norm=i!=board[k]&&i+level-k!=board[k]&&i-level+k!=board[k];if(norm){board[level++]=i;ans=this;}returnan
6、s;}publicNodeup(){--level;returnthis;}publicintsubnodenum(){returnlevel7、ublicintsubnodenum(){returnlevel=level8、9、perm[k]!=i;}if(ans){perm[level++]=i;returnthis;}elsereturnnull;
7、ublicintsubnodenum(){returnlevel=level
8、
9、perm[k]!=i;}if(ans){perm[level++]=i;returnthis;}elsereturnnull;
此文档下载收益归作者所有