-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaek_9095.py
More file actions
42 lines (37 loc) · 1.01 KB
/
baek_9095.py
File metadata and controls
42 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
문제
정수 4를 1, 2, 3의 합으로 나타내는 방법은 총 7가지가 있다. 합을 나타낼 때는 수를 1개 이상 사용해야 한다.
1+1+1+1
1+1+2
1+2+1
2+1+1
2+2
1+3
3+1
정수 n이 주어졌을 때, n을 1, 2, 3의 합으로 나타내는 방법의 수를 구하는 프로그램을 작성하시오.
입력
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 정수 n이 주어진다. n은 양수이며 11보다 작다.
출력
각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다.
"""
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t) :
n = int(input())
if n == 1 :
print(1)
continue
elif n == 2 :
print(2)
continue
elif n == 3 :
print(4)
continue
dp = [0] * (n+1)
dp[1] = 1
dp[2] = 2
dp[3] = 4
for i in range(4, n+1) :
dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
print(dp[n])