ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
2193๋ฒ: ์ด์น์
0๊ณผ 1๋ก๋ง ์ด๋ฃจ์ด์ง ์๋ฅผ ์ด์ง์๋ผ ํ๋ค. ์ด๋ฌํ ์ด์ง์ ์ค ํน๋ณํ ์ฑ์ง์ ๊ฐ๋ ๊ฒ๋ค์ด ์๋๋ฐ, ์ด๋ค์ ์ด์น์(pinary number)๋ผ ํ๋ค. ์ด์น์๋ ๋ค์์ ์ฑ์ง์ ๋ง์กฑํ๋ค. ์ด์น์๋ 0์ผ๋ก ์์ํ์ง ์
www.acmicpc.net
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2193
/*
N = 1์ผ๋ count = 1
1
N = 2์ผ๋ count = 1
10
N = 3์ผ๋ count = 2
100
101
N = 4์ผ๋ count = 3
1000
1010
1001
N = 5์ผ๋ count = 5
10000
10100
10101
10010
10001
N = 6์ผ๋ count = 8
100000
101000
101010
101001
100100
100101
100010
100001
...
*/
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var count = make([]int, n+1)
for i := 1; i < n+1; i++ {
if i < 2 {
count[i] = 1
} else {
count[i] = count[i-1] + count[i-2]
}
}
fmt.Fprintln(writer, count[n])
}
๐จ Python3
# https://www.acmicpc.net/problem/2193
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
count = [0 for i in range(n+1)]
for i in range(1, n+1):
if i < 2:
count[i] = 1
else:
count[i] = count[i-1] + count[i-2]
print(count[n])
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 11727๋ฒ / 2รn ํ์ผ๋ง 2 [Go][Python3] (0) | 2021.01.13 |
---|---|
BOJ / 11726๋ฒ / 2รn ํ์ผ๋ง [Go][Python3] (0) | 2021.01.12 |
BOJ / 9095๋ฒ / 1, 2, 3 ๋ํ๊ธฐ [Go][Python3] (0) | 2021.01.10 |
BOJ / 1024๋ฒ / ์์ด์ ํฉ [Go][Python3] (0) | 2021.01.09 |
BOJ / 1004๋ฒ / ์ด๋ฆฐ ์์ [Go][Python3] (0) | 2021.01.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์ด๋ถํ์
- dp
- BFS
- dfs
- Algorithm
- MongoDB
- ๋งฅ๋ถํ๋ก
- ํ
- ๋ธ๋ฃจํธํฌ์ค
- ํด์๋งต
- ํ๋ก์ด๋์์ฌ
- Macbook pro 2012 mid 13
- python3
- baekjoon
- ์๊ณ ๋ฆฌ์ฆ
- ์๋ฐ
- Golang
- BOJ
- ๋ชฝ๊ณ ๋๋น
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์๊ฐ๊ต์ฒด
- ๋ฐฑ์ค
- AWS
- ๋ฐ๋
- ๋ถํ ์ ๋ณต
- go
- java
- ballet
- ์คํ
- ๋งฅ๋ถ
- Total
- Today
- Yesterday