Skip to content

[강신지-14주차 알고리즘 스터디] #29

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

Open
wants to merge 15 commits into
base: akstp1717/week14
Choose a base branch
from

Conversation

ksinji
Copy link
Contributor

@ksinji ksinji commented May 18, 2025

🚀 싸피 15반 알고리즘 스터디 14주차 [강신지

📌 문제 풀이 개요

  • 이번 PR에서는 다음 5문제의 풀이를 포함합니다.
  • 각 문제에 대한 풀이 과정과 접근 방식을 설명합니다.

✅ 문제 해결 여부

  • 문제 1
  • 문제 2
  • 문제 3
  • 문제 4
  • 문제 5

💡 풀이 방법

문제 1: 양팔저울

문제 난이도
골드 3

문제 유형
DP

접근 방식 및 풀이
DFS로 추를 왼쪽, 오른쪽에 놓거나 사용하지 않는 세 가지 경우를 탐색하면서 만들 수 있는 무게 차이를 기록하는 방식으로 해결했습니다.

static void solve(int idx, int weight) {
    if (idx > N || dp[idx][weight]) return;

    dp[idx][weight] = true;

    if (idx == N) return;

    solve(idx + 1, weight); // 추 사용 안함
    solve(idx + 1, weight + weights[idx]); // 오른쪽에 놓음
    solve(idx + 1, Math.abs(weight - weights[idx])); // 왼쪽에 놓음
}

문제 2: 제곱수의 합

문제 난이도
실버 2

문제 유형
DP

접근 방식 및 풀이
1부터 N까지 순차적으로 탐색하며, i보다 작거나 같은 제곱수를 기준으로 최소 횟수를 갱신하는 DP로 해결했습니다.

int[] dp = new int[N + 1];

for (int i = 1; i <= N; i++) {
    dp[i] = i;
    for (int j = 1; j * j <= i; j++) {
        dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
    }
}

문제 5 : 타일 채우기

문제 난이도
골드 4

문제 유형
DP

접근 방식 및 풀이
3×N 타일을 채우는 경우를 점화식으로 구성하고, 이전 짝수 길이에서 파생되는 특수 케이스들을 누적하여 DP로 해결했습니다.

int[] dp = new int[n + 1];
dp[0] = 1; // 초기값 설정
dp[2] = 3;

for (int i = 4; i <= n; i += 2) {
    dp[i] = dp[i - 2] * 3;
    for (int j = i - 4; j >= 0; j -= 2) {
        dp[i] += dp[j] * 2;
    }
}

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.

1 participant