https://www.youtube.com/watch?v=zasMkhSD2pc&list=PLodgw23vNd_U66omABrprSwJBZhKPFGMM&index=2
답안
def dfs(index, cnt, total):
global answer
A = 12
# 가지치기
if total>K:
return
# 종료 조건
if index==A:
if total==K and cnt==CNT:
answer+=1
return
dfs(index+1, cnt+1, total+index+1)
dfs(index+1, cnt, total)
T = int(input())
for test_case in range(1, T+1):
CNT, K = list(map(int, input().split()))
answer = 0
dfs(0,0,0)
print(f"#{test_case} {answer}")
'알고리즘 > Python' 카테고리의 다른 글
[Python | SWEA] 1486. 장훈이의 높은 선반 (0) | 2023.05.18 |
---|---|
[Python | SWEA] 4881. [파이썬 S/W 문제해결 기본] 5일차 - 배열 최소 합 (0) | 2023.05.18 |
[Python | SWEA] 1873. 상호의 배틀필드 (0) | 2023.05.17 |
[Python | SWEA] 1221. [S/W 문제해결 기본] 5일차 - GNS (0) | 2023.05.16 |
[Python | SWEA] 5215. 햄버거 다이어트 (0) | 2023.05.16 |