Skip to content

Commit c3fdbb8

Browse files
committed
[Silver III] Title: 1, 2, 3 더하기, Time: 100 ms, Memory: 14328 KB -BaekjoonHub
1 parent 264e4df commit c3fdbb8

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.*;
2+
3+
public class Main {
4+
static int N;
5+
static Integer[] DP = new Integer[11];
6+
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringBuffer sb = new StringBuffer();
10+
11+
N = Integer.parseInt(br.readLine());
12+
13+
DP[0] = 0;
14+
DP[1] = 1;
15+
DP[2] = 2;
16+
DP[3] = 4;
17+
18+
for(int i=0; i<N; i++){
19+
int num = Integer.parseInt(br.readLine());
20+
for(int j=4; j<=num; j++){
21+
DP[j] = DP[j-1] + DP[j-2] + DP[j-3];
22+
}
23+
sb.append(DP[num] + "\n");
24+
}
25+
System.out.println(sb);
26+
}
27+
28+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# [Silver III] 1, 2, 3 더하기 - 9095
2+
3+
[문제 링크](https://www.acmicpc.net/problem/9095)
4+
5+
### 성능 요약
6+
7+
메모리: 14328 KB, 시간: 100 ms
8+
9+
### 분류
10+
11+
다이나믹 프로그래밍
12+
13+
### 제출 일자
14+
15+
2025년 4월 3일 17:02:49
16+
17+
### 문제 설명
18+
19+
<p>정수 4를 1, 2, 3의 합으로 나타내는 방법은 총 7가지가 있다. 합을 나타낼 때는 수를 1개 이상 사용해야 한다.</p>
20+
21+
<ul>
22+
<li>1+1+1+1</li>
23+
<li>1+1+2</li>
24+
<li>1+2+1</li>
25+
<li>2+1+1</li>
26+
<li>2+2</li>
27+
<li>1+3</li>
28+
<li>3+1</li>
29+
</ul>
30+
31+
<p>정수 n이 주어졌을 때, n을 1, 2, 3의 합으로 나타내는 방법의 수를 구하는 프로그램을 작성하시오.</p>
32+
33+
### 입력
34+
35+
<p>첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 정수 n이 주어진다. n은 양수이며 11보다 작다.</p>
36+
37+
### 출력
38+
39+
<p>각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다.</p>
40+

0 commit comments

Comments
 (0)