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 |
java 怎么总提交出错呢?谁帮帮我看看是不是代码 错了谢谢啊import java.io.*; import java.util.Scanner; public class Main{ private static int n; private static char[][] board; //记录棋盘状态 private static boolean[] place_C; //记录这列是否可以放旗子 private static int count = 0; //方案数 private static int numPlaced = 0; //已放旗子数目 private static int k; //要放的旗子数目 public static void main(String[] args) throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); Scanner s = new Scanner(System.in); while(true) { n = s.nextInt(); k = s.nextInt(); if(n == -1 && k == -1) return; board = new char[n][n]; place_C = new boolean[n]; int r = 0; String test = br.readLine(); while(test!=null) { for(int i=0; i<n; i++) board[r][i] = test.charAt(i); r++; if(r == n) break; test = br.readLine(); } dfs(0); System.out.println(count); count = 0; } } public static boolean canPlace(int i, int j) { return !place_C[j] && board[i][j] == '#'; } public static void dfs(int i) { if(numPlaced == k) { count++; return; } if(i >= n) return; int j; for(j=0; j<n; j++) { if(canPlace(i,j)) { place_C[j] = true; numPlaced++; dfs(i+1); place_C[j] = false; numPlaced--; } } dfs(i+1); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator