๋ฌธ์
https://www.acmicpc.net/problem/10844
ํ์ด
# ๋ฐฑ์ค 10844๋ฒ ๋ฌธ์ - ์ฌ์ด ๊ณ๋จ ์
n = int(input())
dp = [[0]*10 for _ in range(n+1)]
for i in range(1, 10):
dp[1][i] = 1
value = 1000000000
for i in range(2, n+1):
for j in range(10):
if j == 0:
dp[i][j] = dp[i-1][1]
elif j == 9:
dp[i][j] = dp[i-1][8]
else:
dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]
print(sum(dp[n]) % value)
DP๋ฅผ ์ด์ฉํด ๊ท์น์ ์ฐพ์ผ๋ฉด ์ฝ๊ฒ ํ ์ ์๋ ๋ฌธ์ ์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] 11055๋ฒ_๊ฐ์ฅ ํฐ ์ฆ๊ฐ ๋ถ๋ถ ์์ด (0) | 2022.11.28 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] 17413๋ฒ_๋จ์ด ๋ค์ง๊ธฐ 2 (1) | 2022.11.28 |
๐ฉ [๋ฐฑ์ค] [Python] 1325๋ฒ_ํจ์จ์ ์ธ ํดํน (0) | 2022.11.26 |
๐ฉ [๋ฐฑ์ค] [Python] 9205๋ฒ_๋งฅ์ฃผ ๋ง์๋ฉด์ ๊ฑธ์ด๊ฐ๊ธฐ (1) | 2022.11.26 |
๐ฉ [๋ฐฑ์ค] [Python] [DP] 2156๋ฒ_ํฌ๋์ฃผ ์์ (0) | 2022.11.26 |