Skip to content

Commit 49bde45

Browse files
[20251215] BOJ / G5 / 넴모넴모 (Easy) / 설진영
1 parent a0e371d commit 49bde45

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static int N, M;
7+
static boolean[][] grid;
8+
static long count = 0;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
N = Integer.parseInt(st.nextToken());
14+
M = Integer.parseInt(st.nextToken());
15+
grid = new boolean[N][M];
16+
17+
backtrack(0);
18+
System.out.println(count);
19+
}
20+
21+
static void backtrack(int pos) {
22+
if (pos == N * M) {
23+
count++;
24+
return;
25+
}
26+
27+
int row = pos / M;
28+
int col = pos % M;
29+
30+
grid[row][col] = false;
31+
backtrack(pos + 1);
32+
33+
grid[row][col] = true;
34+
if (row > 0 && col > 0 && grid[row-1][col] && grid[row][col-1] && grid[row-1][col-1]) {
35+
grid[row][col] = false;
36+
return;
37+
}
38+
backtrack(pos + 1);
39+
grid[row][col] = false;
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)