Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:java 怎么总提交出错呢?谁帮帮我看看是不是代码 错了谢谢啊

Posted by gedoua at 2009-08-01 15:04:24 on Problem 1321
In Reply To:java 怎么总提交出错呢?谁帮帮我看看是不是代码 错了谢谢啊 Posted by:gedoua at 2009-08-01 15:03:17
> 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator