File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed
Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+
6+ // TIP 코드를 <b>실행</b>하려면 <shortcut actionId="Run"/>을(를) 누르거나
7+ // 에디터 여백에 있는 <icon src="AllIcons.Actions.Execute"/> 아이콘을 클릭하세요.
8+ public class Main {
9+ private static BufferedReader br;
10+ private static int answer;
11+ private static int [][] map;
12+ private static int m;
13+ private static int n;
14+
15+ public static void main (String [] args ) throws IOException {
16+ br = new BufferedReader (new InputStreamReader (System . in));
17+ var temp = br. readLine(). split(" " );
18+ n = Integer . parseInt(temp[0 ]);
19+ m = Integer . parseInt(temp[1 ]);
20+ map = new int [n][m];
21+ answer = 0 ;
22+ dfs(0 );
23+ System . out. println(answer);
24+ br. close();
25+ }
26+
27+ private static void dfs (int idx ) {
28+ // 종료
29+ if (idx == n* m){
30+ answer++ ;
31+ return ;
32+ }
33+ // idx에 네모 없는 것으로 진행
34+ int r = idx / m;
35+ int c = idx % m;
36+ map[r][c] = 0 ;
37+ dfs(idx+ 1 );
38+
39+ if (isValid(idx)){
40+ map[r][c] = 1 ;
41+ dfs(idx+ 1 );
42+ }
43+ }
44+
45+ private static boolean isValid (int idx ) {
46+ int r = idx/ m;
47+ int c = idx% m;
48+ boolean isFirstCol = c == 0 ;
49+ if (isFirstCol) return true ;
50+ if (r == 0 ){
51+ return true ;
52+ }
53+ boolean leftDown = (map[r][c- 1 ] == 1 );
54+ boolean leftUp = (map[r- 1 ][c- 1 ] == 1 );
55+ boolean rightUp = (map[r- 1 ][c] == 1 );
56+ if (leftDown && leftUp && rightUp){
57+ return false ;
58+ }else {
59+ return true ;
60+ }
61+ }
62+ }
63+ ```
You can’t perform that action at this time.
0 commit comments