๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 9184๋ฒ
ํ์ด ๊ณผ์
๋ฉ๋ชจ์ด์ ์ด์
์ผ๋ก ์ฌ๊ท ํธ์ถ์ ์ต์ ํํ๋ ๋ฌธ์ ์
๋๋ค.
๋ฌธ์ ์์ ์ ์๋ ํจ์ ๊ตฌํ์ ๋์ ๊ณํ๋ฒ
์ผ๋ก ๊ตฌํํ๋ฉด ๋ฉ๋๋ค.
์ฝ๋
import sys
memo = [[[-1] * 51 for _ in range(51)] for _ in range(51)]
def func(a, b, c):
if a <= 0 or b <= 0 or c <= 0:
return 1
if a > 20 or b > 20 or c > 20:
return func(20, 20, 20)
if memo[a][b][c] != -1:
return memo[a][b][c]
if a < b < c:
memo[a][b][c] = func(a, b, c - 1) + func(a, b - 1, c - 1) - func(a, b - 1, c)
else:
memo[a][b][c] = func(a - 1, b, c) + func(a - 1, b - 1, c) + func(a - 1, b, c - 1) - func(a - 1, b - 1, c - 1)
return memo[a][b][c]
def solution(a, b, c):
output = func(a, b, c)
return f"w({a}, {b}, {c}) = {output}\n"
if __name__ == '__main__':
while 1:
a, b, c = list(map(int, sys.stdin.readline().split()))
if [a, b, c] == [-1, -1, -1]:
break
answer = solution(a, b, c)
sys.stdout.write(answer)
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 1644 - ์์์ ์ฐ์ํฉ (0) | 2021.03.08 |
---|---|
BOJ 18242 - ๋ค๋ชจ๋ค๋ชจ ์๋ ฅ๊ฒ์ฌ (0) | 2021.03.08 |
BOJ 14226 - ์ด๋ชจํฐ์ฝ (0) | 2021.03.08 |
BOJ 2529 - ๋ถ๋ฑํธ (0) | 2021.03.08 |
BOJ 1802 - ์ข ์ด ์ ๊ธฐ (0) | 2021.03.08 |
๐ฌ ๋๊ธ