๋ฌธ์
https://www.acmicpc.net/problem/11727
11727๋ฒ: 2×n ํ์ผ๋ง 2
2×n ์ง์ฌ๊ฐํ์ 1×2, 2×1๊ณผ 2×2 ํ์ผ๋ก ์ฑ์ฐ๋ ๋ฐฉ๋ฒ์ ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ์๋ ๊ทธ๋ฆผ์ 2×17 ์ง์ฌ๊ฐํ์ ์ฑ์ด ํ๊ฐ์ง ์์ด๋ค.
www.acmicpc.net
๋ด ๋ฌธ์ ํ์ด
n = int(input())
if n == 1:
print(1)
elif n == 2:
print(3)
else:
memory = [1, 3]
for i in range(2, n):
memory.append((memory[i-2]*2 + memory[i-1]) % 10007)
print(memory[-1])
๐ DP ๋ฌธ์ ๋ก, ์ ํ์ / ๋ฉ๋ชจ์ด์ ์ด์ ์ฌ์ฉํด์ฃผ๋ฉด ๋๋ค.
p[n] = p[n-1] + p[n-2]*2 ์ ์ ํ์์ ๋ง๊ฒ ํ์ด์ฃผ์๋ค.
๐ก ํผ๋๋ฐฑ
- ์ ํ์ ๋ฌธ์ ์ง๋ง, n์ ๋ฐ๋ฅธ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํด์ฃผ๋๋ฐ์ ์กฐ๊ธ ์๊ฐ์ ํ ์ ํด์ผ ํ๋ ๋ฌธ์ ์๋ค.
'4๏ธโฃ Python > Problem Solving' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python Algorithm] ๋ฒ ์คํธ์ ๋ฌ BOJ #1302 (0) | 2022.02.03 |
---|---|
[Python Algorithm] ๋จ์ด ์ ๋ ฌ BOJ #1181 (0) | 2022.02.02 |
[Python Algorithm] ์ด์น์ BOJ #2193 (0) | 2022.02.01 |
[Python Algorithm] ํฌ๋์ฃผ ์์ BOJ #2156 (0) | 2022.01.31 |
[Python Algorithm] ์ฐ์ํฉ BOJ #1912 (0) | 2022.01.31 |
๋๊ธ