回溯法的通用算法

</pre><pre code_snippet_id="1563060" snippet_file_name="blog_20160123_2_899283" name="code" class="cpp">void try(n)        //第n步
if(n==maxn)输出并返回    //递归边界
for(int i=0 to x){       //尝试每一种走法
if(可行){         //判断当前走法可不可行
			记录方案
			宣布占领
			try(n+1)
			宣布释放    //回溯,以便另外的方法能走到
		}
	}

你可能感兴趣的:(算法)