ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
package main
import (
"fmt"
"os"
"bufio"
)
func main() {
reader := bufio.NewReader(os.Stdin)
var t int
fmt.Fscanln(reader, &t)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
for i :=0; i<t; i++ {
var n int
fmt.Fscanln(reader, &n)
lengths := calculate(n)
fmt.Fprintf(writer, "%d\n", lengths[n-1])
}
}
func calculate(n int) (lengths []int) {
lengths = append(lengths, 1, 1, 1)
if n <= 3 {
return
}
for i := 3; i < n+1 ; i++ {
lengths = append(lengths, lengths[i-2]+ lengths[i-3])
}
return
}
๐จ Python3
import sys
def calculate(n):
lengths = [1, 1, 1]
if n <= 3:
return lengths
for i in range(3, n+1):
lengths.append(lengths[i-2]+lengths[i-3])
return lengths
if __name__ == "__main__":
t = int(sys.stdin.readline())
for i in range(t):
n = int(sys.stdin.readline())
lengths = calculate(n)
print(lengths[n-1])
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1932๋ฒ / ์ ์ ์ผ๊ฐํ [Python3] (0) | 2020.11.03 |
---|---|
BOJ / 1149๋ฒ / RGB๊ฑฐ๋ฆฌ [Go] [Python3] (0) | 2020.08.04 |
BOJ / 1904๋ฒ / 01ํ์ผ [Go] [Python3] (0) | 2020.08.02 |
BOJ / 1003๋ฒ / ํผ๋ณด๋์น ํจ์ [Go] (0) | 2020.08.01 |
BOJ / 2748๋ฒ / ํผ๋ณด๋์น ์ 2 [Go] (0) | 2020.07.31 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- MongoDB
- ๋ชฝ๊ณ ๋๋น
- Algorithm
- ballet
- dp
- ํ
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- ๋ฐฑ์ค
- ๋งฅ๋ถํ๋ก
- baekjoon
- ์๊ฐ๊ต์ฒด
- ํ๋ก์ด๋์์ฌ
- Macbook pro 2012 mid 13
- go
- ๋ฐ๋
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถ
- Golang
- ํด์๋งต
- python3
- ์คํ
- BFS
- ์๋ฐ
- ์ด๋ถํ์
- java
- BOJ
- AWS
- dfs
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- Total
- Today
- Yesterday