Seek/알고리즘 문제풀이

9461번 파도반 수열 (Python3)

asc3nd 2019. 8. 29. 20:04

 

소스코드

1
2
3
4
5
6
7
8
9
10
11
import sys
 
loop = int(sys.stdin.readline())
for _ in range(loop):
  n = int(sys.stdin.readline())
  a, b, c, result = 1111
  for i in range(3, n):
    result = a+b
    a, b = b, c
    c = result
  print(result)
cs

1, 1, 1, 2, 2, 3, 4, 5, 7, ....

d[n] = d[n-2] +d[n-3]