标签:ble turn static put util int() pre input tput
棋盘问题
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 73545 | Accepted: 34682 |
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
Java AC 代码:
1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main { 5 static char [][]maze = new char [10][10]; 6 static int []vis = new int [10]; 7 static int n,m,cnt; 8 public static void main(String[] args) { 9 Scanner cin = new Scanner(System.in); 10 while(cin.hasNext()) { 11 Arrays.fill(vis,0); 12 n = cin.nextInt(); 13 m = cin.nextInt(); 14 if(m == -1 && n == -1) 15 break; 16 cnt = 0; 17 for(int i = 1;i <= n;i++) { 18 String s = cin.next(); 19 for(int j = 1;j <= n;j++) { 20 maze[i][j] = s.charAt(j - 1); 21 } 22 } 23 DFS(1,0); 24 System.out.println(cnt); 25 } 26 } 27 28 private static void DFS(int row,int step) { 29 if(row > n + 1) 30 return ; 31 if(step == m) { 32 cnt++; 33 return ; 34 } 35 for(int i = 1;i <= n;i++) { 36 if(maze[row][i] == ‘#‘ && vis[i] == 0) 37 { 38 vis[i] = 1; 39 DFS(row + 1,step + 1); 40 vis[i] = 0; 41 } 42 } 43 DFS(row + 1,step); 44 } 45 }
标签:ble turn static put util int() pre input tput
原文地址:https://www.cnblogs.com/youpeng/p/10306310.html