백준 9148 신나는 함수 실행

김민영·2023년 1월 20일
0

알고리즘

목록 보기
87/125

과정

  • 주어진 수도코드를 그대로 작성하면 되는 문제였다.
  • 재귀 사이에 dp를 넣는 느낌

참고
https://jainn.tistory.com/82

dp = [[[0] * 21 for _ in range(21)] for _ in range(21)]

def main(a, b, c):
    if a <= 0 or b <= 0 or c <= 0:
        return 1
    if a > 20 or b > 20 or c > 20:
        return main(20, 20, 20)
    if dp[a][b][c] != 0:
        return dp[a][b][c]
    if a < b and b < c:
        dp[a][b][c] = main(a, b, c - 1) + main(a, b - 1, c - 1) - main(a, b - 1, c)
    else:
        dp[a][b][c] = main(a - 1, b, c) + main(a - 1, b - 1, c) + main(a - 1, b, c - 1) - main(a - 1, b - 1, c - 1)
    return dp[a][b][c]

while True:
    a, b, c = map(int, input().split())
    if a == -1 and a == b==c:
        break
    print(f'w({a}, {b}, {c}) = {main(a, b, c)}')
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글