728x90
반응형

브루트포스 알고리즘 & 백트래킹 문제이다. PyPy3로 제출해야 통과된다.

depth > 1 and li[depth-2] == li[depth-1] == i(현재 선택한 답과 그 전의 2개의 답이 같음) 조건을 성립하지 않는

답을 추가하고, 정답을 10개 다 선택했다면 점수를 확인하고 3 이상이라면 cnt를 올려주면 된다. 

def dfs(depth):
    global cnt
    if depth == 10:
        s = 0
        for j in range(10):
            if li[j] == ans[j]:
                s += 1
        if s >= 5:
            cnt += 1
        return ;
    for i in range(1, 6):
        if depth > 1 and li[depth-2] == li[depth-1] == i:
            continue
        li.append(i)
        dfs(depth+1)
        li.pop()
        
ans = list(map(int, input().split()))
li, cnt = [], 0
dfs(0)
print(cnt)
728x90
반응형

+ Recent posts