본문 바로가기
Algorithm(CodeTree, Python)/Backtracking

[코드트리] 1차원 윷놀이 Python

by kurooru 2023. 1. 31.
# n, m, k 입력
n, m, k = map(int, input().split())
# jump_list
jump_list = list(map(int, input().split()))

# calc(cubb_comb)
def calc(curr_comb):
    # horses
    horses = [0, 0, 0, 0]

    # 이동시키기
    for i in range(n):
        horses[comb[i]] += jump_list[i]
    
    # curr_point
    curr_point = 0

    # 전부 이동시킨 말들을 확인
    for horse in horses:
        # 도착했으면
        if horse >= m-1:
            # curr_point 올려주기
            curr_point += 1
    
    # 반환
    return curr_point

# make_comb(curr_idx)
def make_comb(curr_idx):
    
    # 전역 변수 선언
    global max_point

    # 종료조건
    if curr_idx == n+1:
        # max_point update
        max_point = max(max_point, calc(comb))
        return
    # 순서 짜기
    for i in range(k):
        comb.append(i)
        make_comb(curr_idx + 1)
        comb.pop()

# 설계
# max_point
max_point = 0
# comb
comb = []
# make_comb()
make_comb(1)

# 출력
print(max_point)