๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/2688)
< ์ค์ด๋ค์ง ์์ >
๋ฌธ์ ํ์ด
์ค์ด๋ค์ง ์๋ ์๋ฅผ ๊ตฌํ๊ธฐ ์ํด ํ์ฌ ์๋ฆฌ์์ (ํ์ฌ ์๋ฆฌ-1)์ด ์์ ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๊ฒฝ์ฐ๋ฅผ ํฉํ๋ค.
my solution (Java)
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class _2688_ { // ์ค์ด๋ค์ง ์์
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
long dp[][] = new long[65][10];
for (int i = 0; i < 10; i++) {
dp[1][i] = 1;
}
for (int i = 2; i < 65; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k <= j; k++) {
dp[i][j] += dp[i - 1][k];
}
}
}
int t = Integer.parseInt(bf.readLine());
for (int i = 0; i < t; i++) {
int n = Integer.parseInt(bf.readLine());
long result = 0;
for (int j = 0; j < 10; j++) {
result += dp[n][j];
}
bw.write(result + "\n");
}
bw.flush();
}
}
๋ณ์)
dp : ์ค์ด๋ค์ง ์๋ n์๋ฆฌ์ ์ ๊ฐ์
t : ํ ์คํธ ์ผ์ด์ค์ ๊ฐ์
n : ๊ฐ ํ ์คํธ ์ผ์ด์ค
result : ์ค์ด๋ค์ง ์๋ n์๋ฆฌ ์์ ๊ฐ์
์ ๋ ฅ๊ฐ์ผ๋ก ๋ค์ด์ฌ ์ ์๋ ์ต๋ n๊ฐ์ด 64์ด๋ฏ๋ก ๋จผ์ , ์ต๋๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ค์ด๋ค์ง ์๋ ์๋ฆฟ์์ ๊ฐ์๋ฅผ ๊ตฌํ๋ค. ํ ์คํธ ์ผ์ด์ค ๊ฐ์๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. ํ ์คํธ ์ผ์ด์ค ๊ฐ์๋งํผ ๊ฐ์ ์ ๋ ฅ๋ฐ์ n์๋ฆฌ์ 0๋ถํฐ 9๊น์ง ๊ฐ์ ํฉํด ์ถ๋ ฅํ๋ค.
* long์ ์จ์ผ ํ๋ค.

'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Baekjoon] 9711_ํผ๋ณด๋์น (0) | 2026.01.09 |
|---|---|
| [Baekjoon] 1965_์์๋ฃ๊ธฐ (0) | 2026.01.08 |
| [Baekjoon] 2294_๋์ 2 (0) | 2026.01.07 |
| [Baekjoon] 11054_๊ฐ์ฅ ๊ธด ๋ฐ์ดํ ๋ ๋ถ๋ถ ์์ด (0) | 2026.01.06 |
| [Baekjoon] 14442_๋ฒฝ ๋ถ์๊ณ ์ด๋ํ๊ธฐ 2 (0) | 2026.01.05 |