POJ1321

题目链接:http://poj.org/problem?id=1321

 

package Search;

import java.util.*;
public class POJ1321 {

	static int c;//结果
	static int n,k;
	static boolean[][] map;//用数组来标记地图形状
	static boolean[] used;//标记器
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			c = 0;
			n = sc.nextInt();
			k = sc.nextInt();
			
			if(n==-1 && k==-1)return;
			
			map = new boolean[n+1][n+1];
			used = new boolean[n+1];
			
			for(int i = 1; i<=n;i++){
				String temp = sc.next();
				for(int j = 0;jn)return;//搜索越界,搜索结束
		
		for(int i = 1;i<=n;i++){
			if(map[row][i] && !used[i]){
				used [i] = true;//标记该行已经放置棋子
				dfs(row+1,num+1);
				
				used [i] = false;//回溯
			}
		}
		
		dfs(row+1,num);//这里是难点,当k


 

你可能感兴趣的:(string,c++,class,图形,c)