Skip to content

Commit c33020e

Browse files
Merge pull request #2077 from CodingTestStudy2/변지협
[변지협] Day23
2 parents 8959c41 + 4eebd26 commit c33020e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
1. 아이디어 :
3+
점화식 T(n) = T(n-1) + T(n-2) + T(n-3) 을 그대로 DP로 옮긴다.
4+
dp[0]=0, dp[1]=1, dp[2]=1 을 초기값으로 두고 n까지 채운 뒤 dp[n]을 반환.
5+
6+
2. 시간복잡도 :
7+
o(n) - n까지 한 번만 순회
8+
9+
3. 자료구조/알고리즘 :
10+
DP (1차원 배열), 점화식
11+
12+
'''
13+
14+
class Solution:
15+
def tribonacci(self, n: int) -> int:
16+
dp = [0] * 40
17+
18+
dp[0] = 0
19+
dp[1] = 1
20+
dp[2] = 1
21+
22+
for i in range(2,n+1):
23+
dp[i] = dp[i-1] + dp[i-2] + dp[i-3]
24+
25+
return dp[n]

0 commit comments

Comments
 (0)