[20250826] BOJ / G5 / 1, 2, 3 더하기 4 / 이인희#750
Merged
ShinHeeEul merged 1 commit intomainfrom Aug 26, 2025
Merged
Conversation
Contributor
Author
|
점화식 잘못 세웠었습니다... 제가 의도했던 방식으로 푸니 클리어했습니다. import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static BufferedReader br;
private static int t;
private static int n;
private static int[][] dp;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
t = Integer.parseInt(br.readLine());
int maxN = 10000;
dp = new int[4][maxN + 1];
dp[1][1] = 1; //1
dp[1][2] = 1; //1+1
dp[2][2] = 1; //2
dp[1][3] = 1; //1+1+1
dp[2][3] = 1; //2+1
dp[3][3] = 1; //3
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= maxN; j++) {
dp[0][j] += dp[i][j];
}
}
for (int i = 4; i <= maxN; i++) {
//맨 앞 항이 3 -> 3 + (i-3을 나머지를 1,2,3으로 만듦)
dp[3][i] = dp[0][i - 3];
// 맨 앞 항이 2 -> 2 + (i-2를 나머지를 2, 1으로 만듦)
dp[2][i] = dp[2][i - 2] + dp[1][i - 2];
// 맨 앞 항이 1 -> 1 + (i-1을 나머지를 1으로 만듦)
dp[1][i] = dp[1][i - 1];
dp[0][i] = dp[1][i] + dp[2][i] + dp[3][i];
}
StringBuilder sb = new StringBuilder();
for(int tt = 0; tt<t; tt++) {
n = Integer.parseInt(br.readLine());
sb.append(dp[0][n]).append("\n");
}
System.out.print(sb);
br.close();
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/15989
🧭 풀이 시간
40 분
👀 체감 난이도
✏️ 문제 설명
🔍 풀이 방법
⏳ 회고