๋ฌธ์
https://www.acmicpc.net/problem/2225
ํ์ด
# ๋ฐฑ์ค 2225๋ฒ ๋ฌธ์ - ํฉ๋ถํด
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
dp = [[0]*201 for _ in range(201)]
for j in range(201):
dp[1][j] = 1
dp[2][j] = j + 1
for i in range(2, 201):
dp[i][1] = i
for j in range(2, 201):
dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % 1000000000
print(dp[k][n])
DP ๋ฌธ์ ์ธ๋ฐ ์ ํ์์ ์ฐพ๋๋ฐ ๋๋ฌด ์ค๋๊ฑธ๋ ธ๋ค.
n๊ณผ k์ ๊ด๊ณ์ ๋ํด ์๊ฐํด๋ด์ผ ํ๋ค.
i \ j | n = 0 | n = 1 | n = 2 | n = 3 |
k = 0 | 0 | 0 | 0 | 0 |
k = 1 | 1 (0) | 1 (1) -> ์๊ธฐ ์์ | 1 | 1 |
k = 2 | 1 (0,0) | 2 (0,1) (1,0) | 3 | 4 |
k = 3 | 1 | 3 (0,0,1) (0,1,0) (1,0,0) | 6 | 10 |
์์ ๊ทธ๋ํ๋ฅผ ๋ณด๋ฉด k = 0 ์ผ๋ ํฉ์ด n์ด ๋๋ ์๋ ์ฐพ์ ์ ์๋ค.
๋ค์์ผ๋ก ๋์ด๊ฐ์ k = 1์ผ ๋๋ n๊ณผ ๊ด๊ณ์์ด n ์์ ์ ์ ํํ๋ ๋ฐฉ๋ฒ๋ฐ์ ์กด์ฌํ์ง ์์ ๋ชจ๋ 1๊ฐ์ง์ด๋ค.
k = 2 ์ผ ๋๋ n + 1์ด๋ผ๋ ์ ํ์์ ๊ตฌํ ์ ์๋ค.
k = 3 ์ผ ๋๋ dp[ i ] [ j ] = dp[ i - 1 ][ j ] + dp[ i ][ j - 1 ] ์ด๋ผ๋ ์ ํ์์ด ์ฑ๋ฆฝ๋๋ค.
ํ๋ฅผ ๊ทธ๋ ค์ ๊ตฌํ๋ฉด ๋งค์ฐ ์ฌ์ ๋๋ฐ ๋ณต์กํ๊ฒ ์๊ฐํ ํ์๊ฐ ์์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2565๋ฒ_์ ๊น์ค (0) | 2023.04.29 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 2638๋ฒ_์น์ฆ (1) | 2023.04.28 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1916๋ฒ_์ต์๋น์ฉ ๊ตฌํ๊ธฐ (0) | 2023.04.27 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 5582๋ฒ_๊ณตํต ๋ถ๋ถ ๋ฌธ์์ด (0) | 2023.04.26 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver1] 6588๋ฒ_๊ณจ๋๋ฐํ์ ์ถ์ธก (0) | 2023.04.25 |