Algorithm(CodeTree, Python)/완전탐색3

[코드트리 상황을 일일이 가정해보고 진행하는 완전탐색] 야바위 Python

kurooru 2022. 12. 26. 11:01
# n 입력
n = int(input())
# order_list
order_list = []
# a, b, c 입력
for _ in range(n):
    order_list.append(tuple(map(int, input().split())))

# 함수들
# simulate(k)
def simulate(k):
    
    # curr_cups
    curr_cups = [0] * 3
    
    # 조약돌 넣기
    curr_cups[k] = 1
    
    # curr_point
    curr_point = 0
    
    # simulation
    for i in range(n):
        
        # unpacking
        a, b, c = order_list[i]
        a, b, c = a-1, b-1, c-1

        # temp_1, temp_2
        temp_1, temp_2 = curr_cups[a], curr_cups[b]

        # 바꿔주기
        curr_cups[b] = temp_1
        curr_cups[a] = temp_2

        # c번 위치에 조약돌이 있으면
        if curr_cups[c]:
            # curr_point 올려주기
            curr_point += 1
    
    # 반환
    return curr_point

# 설계
# max_point
max_point = 0

# 완전 탐색 시작 (조약돌을 넣을 컵 선택)
for i in range(3):
    
    # max_point update
    max_point = max(max_point, simulate(i))

# 출력
print(max_point)