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

## Java

Posted by 201722362014068 at 2019-03-22 01:45:55 on Problem 1321
```import java.util.Scanner;

public class Main {

private static char[][] c;//记录信息
private static int sum;//总共的方案
private static int k;//棋盘的棋子个数
private static int n;//棋盘的大小
private static int m;//已放入棋盘的棋子数目
private static int[] visit;//每一列是否被放过

public static void dfs(int line) {
if(m==k) {
sum++;
return;
}
if(line>=n) {
return;
}
for(int j=0;j<n;j++) {
if((visit[j]==0)&&(c[line][j]=='#')){
visit[j]=1;
m=m+1;
dfs(line+1);
visit[j]=0;
m=m-1;
}

}
dfs(line+1);
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);

while((n=in.nextInt())!=-1&&(k=in.nextInt())!=-1) {
c = new char[n][n];
sum=0;
m=0;
visit=new int[n];
for(int i=0;i<visit.length;i++) {
visit[i]=0;
}
for(int i=0;i<n;i++) {
String s = in.next();
char[] p = s.toCharArray();
for(int j=0;j<p.length;j++) {
c[i][j] = p[j];
}

}
dfs(0);
System.out.println(sum);

}

}

}

```

Followed by: