Part6.6_완전탐색_깊이,넓이 우선탐색활용_알파코드(DFS)

Eugenius1st·2022년 2월 7일
0

Python_algorithm

목록 보기
49/83

선생님 코드

import sys
sys.stdin = open("input.txt", "rt")

def DFS(L, P):
    global cnt
    if L == n:
        cnt +=1
        for j in range(P):
            print(res[j], end=' ')
        print

        return
    elif L == n : 
        for i in range(1,27):
            if code[L] == i:
                res[P] = i
                DFS(L+1, P+1)
            elif i >= 10 and code[L]==i//10 and code[L+1]==i%10:
                res[P] = i
                DFS[L+2, P+1]
                
         
if __name__ == "__main__":
    code = list(map(int,input()))
    n = len(code) # 종착점
    code.insert(n, -1) #맨 뒷 줄에 -1 추가?  >> L과 L+1까지 확인하므로 out of index오류가 나지 않도록 하기 위해서
    res = [0] * (n+3)
    cnt = 0
    DFS(0,0)
    print(cnt)  

다시 풀어보자 !! 조건 저런식으로 많이 줘도 된다는 점 배웠네

profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글