Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이승헌 / 10월 3주차 / 목 #287

Merged
merged 1 commit into from
Oct 23, 2023
Merged

Conversation

olrlobt
Copy link
Contributor

@olrlobt olrlobt commented Oct 19, 2023


🎈boj 17297 - Messi Gimossi


🗨 해결방법 :


Moo 문제와 비슷하게 풀었습니다.
전체 길이를 먼저 구하고, 재귀로 해결하였습니다.

📝메모 :


✔코드 :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

    private static final int MESSI_NUM = 5;
    private static final int SPACE_NUM = 1;
    private static final int GIMOSSI_NUM = 7;
    private static final String MG = " Messi Gimossi";
    private static ArrayList<Integer> dp = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());

        char solve = solve(N, getLeng(N));
        System.out.println(solve == ' ' ? "Messi Messi Gimossi" : solve);
    }

    private static int getLeng(int n) {
        dp.add(0);
        dp.add(MESSI_NUM);
        dp.add(MESSI_NUM + SPACE_NUM + GIMOSSI_NUM);

        int idx = 1;
        while (n > dp.get(++idx)) {
            dp.add(dp.get(idx - 1) + SPACE_NUM + dp.get(idx));
        }
        return idx - 1;
    }

    private static char solve(int N, int idx) {
        int i = 0;
        for(;dp.get(i) < N; i++);
        idx = i-1;

        if (N <= 13) {
            return MG.charAt(N);
        }

        if (N < dp.get(idx)) { // 왼쪽
            return solve(N, idx - 1);
        } else if (N > dp.get(idx) + SPACE_NUM) { // 오른쪽
            return solve(N - dp.get(idx) - SPACE_NUM, idx - 2);
        } else { // 공백
            return ' ';
        }
    }
}


🎈boj 15989 - 1, 2, 3 더하기 4


🗨 해결방법 :


냅색으로 동전문제와 비슷하게 해결하려고 했으나 시간초과로 해결하지 못했습니다.

📝메모 :


✔코드 :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int T = Integer.parseInt(br.readLine());
        for (int testCase = 0; testCase < T; testCase++) {
            sb.append(solve(Integer.parseInt(br.readLine()))).append("\n");
        }
        System.out.println(sb);
    }

    private static int solve(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, 1);

        for (int sum = n; sum >= 0; sum--) {
            for (int j = sum - 2; j >= 0; j -= 2) {
                dp[sum] += dp[j];
            }
        }

        for (int j = n - 3; j >= 0; j -= 3) {
            dp[n] += dp[j];
        }
        return dp[n];
    }


}

@olrlobt olrlobt requested review from nahokyun and skagmltn7 October 19, 2023 10:31
@olrlobt olrlobt changed the title 이승헌 / 10월 3주차 / 목요일 이승헌 / 10월 3주차 / 목 Oct 19, 2023
@olrlobt olrlobt merged commit 19357f4 into SSAFY-10th-Seoul17:main Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants