https://www.acmicpc.net/problem/11051
์ด๊ธฐ์ฝ๋
n, k = map(int,input().split())
def fun(n,k):
if k==n or k==0:
return 1
else:
return fun(n-1,k-1)+fun(n-1,k)
print(fun(n,k)%10007)
์๊ฐ์ด๊ณผ๋๋ค
์ฌ๊ท(๋ฉ๋ชจ์ด์ ์ด์ )
import sys
n, k = map(int,input().split())
sys.setrecursionlimit(10**7)
cache = [[0]*1001 for _ in range(1001)]
def fun(n,k):
if cache[n][k]:
# 0์ด ์๋ ์๋ผ๋ฉด
return cache[n][k]
if k==n or k==0:
cache[n][k]= 1
else:
cache[n][k] = fun(n-1,k-1)+fun(n-1,k)
return cache[n][k]
print(fun(n,k)%10007)
์ด๋ฒ์ ๋ฐํ ์ ๋ฐฉ์์ธ ๋ฐ๋ณต๋ฌธ์ผ๋ก ํ์ด๋ณด์ (ํ๋ทธ๋ ์ด์ )
n, k = map(int,input().split())
cache = [[0]* 1001 for _ in range(1001)]
for i in range(1001):
cache[i][0] = cache[i][i] =1
for j in range(1, i):
cache[i][j] = cache[i-1][j-1] + cache[i-1][j]
print(cache[n][k] %10007)
'๐ฏ์๊ณ ๋ฆฌ์ฆ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค/Python] 10844:์ฌ์ด ๊ณ๋จ ์ (0) | 2024.06.27 |
---|---|
[๋ฐฑ์ค/Python] 11726:2รn ํ์ผ๋ง (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 2748:ํผ๋ณด๋์น ์ 2 (0) | 2024.06.27 |
[๋ฐฑ์ค/Python] 11399:ATM ์ธ์ถ์๊ฐ ๊ณ์ฐํ๊ธฐ (1) | 2023.07.01 |
4-3 ์ฝ์ ์ ๋ ฌ (0) | 2023.07.01 |