Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

전공공부

[BOJ_14712] 넴모넴모 (Easy) 본문

Study/Problem Solving

[BOJ_14712] 넴모넴모 (Easy)

monitor 2023. 10. 10. 22:21

설명


결국 2*2 사각형을 만들지 않으면 되는 것이므로 반대로 생각하면 되었다... 처음 접근만 잘한다면 쉽게 풀 수 있는 문제였다.

코드


package backtracking;

import java.io.*;
import java.util.*;

public class BOJ_14712 {
    static int N;
    static int M,ans;
    static boolean map[][];
    public static void main(String[] args) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tk = new StringTokenizer(in.readLine()," ");

        N = Integer.parseInt(tk.nextToken());
        M = Integer.parseInt(tk.nextToken());
        //반대로 생각하자... -> map[x - 1][y] == true && map[x][y - 1] == true && map[x - 1][y - 1] == true 이 경우만 피하면 되는 것이다..
        map = new boolean[N+1][M+1];

        ans = 0;
        go(0);
        System.out.println(ans);
    }

    private static void go(int idx) {
        if(idx == N*M){
            ans++;
            return;
        }
        else{
            int x = (idx / M) + 1;
            int y = (idx % M) + 1;
            if(map[x - 1][y] == true && map[x][y - 1] == true && map[x - 1][y - 1] == true)
            {
                go(idx+1);
            }else{
                map[x][y] = true;
                go(idx+1);
                map[x][y] = false;
                go(idx+1);
            }
        }
    }

}
 

14712번: 넴모넴모 (Easy)

네모는 뿌××× 게임에 깊은 감명을 받아, 직사각형 모양의 격자판과 “넴모”라는 수수께끼의 생물을 이용하는 “넴모넴모”라는 게임을 만들었다. 이 게임의 규칙은 아주 간단하다. 격자판의

www.acmicpc.net

 

'Study > Problem Solving' 카테고리의 다른 글

[BOJ_3980] 선발 명단  (0) 2023.10.12
[BOJ_1174] 줄어드는 수  (1) 2023.10.11
[BOJ_16987] 계란으로 계란치기  (0) 2023.10.09
[BOJ_14888] 연산자 끼워넣기  (0) 2023.10.08
[BOJ_10971] 외판원 순회 2  (0) 2023.10.05