File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ static int N , M ;
8+ static boolean [][] map;
9+ static int answer = 0 ;
10+
11+ public static void main (String [] args ) throws Exception {
12+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
13+ StringTokenizer st = new StringTokenizer (br. readLine());
14+
15+ N = Integer . parseInt(st. nextToken());
16+ M = Integer . parseInt(st. nextToken());
17+
18+ map = new boolean [N ][M ];
19+
20+ dfs(0 , 0 );
21+
22+ System . out. println(answer);
23+ }
24+
25+ static void dfs (int r , int c ) {
26+ if (r == N ) {
27+ answer++ ;
28+ return ;
29+ }
30+
31+ int nr = r;
32+ int nc = c + 1 ;
33+ if (nc == M ) {
34+ nr = r + 1 ;
35+ nc = 0 ;
36+ }
37+
38+ dfs(nr, nc);
39+
40+ map[r][c] = true ;
41+
42+ if (! hasFull2x2()) {
43+ dfs(nr, nc);
44+ }
45+
46+ map[r][c] = false ;
47+ }
48+
49+ static boolean hasFull2x2 () {
50+ for (int i = 0 ; i < N - 1 ; i++ ) {
51+ for (int j = 0 ; j < M - 1 ; j++ ) {
52+ if (map[i][j] && map[i + 1 ][j] && map[i][j + 1 ] && map[i + 1 ][j + 1 ]) {
53+ return true ;
54+ }
55+ }
56+ }
57+ return false ;
58+ }
59+ }
60+ ```
You can’t perform that action at this time.
0 commit comments