인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

modestajihyelee0969's profile image
modestajihyelee0969

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

6. Finding duplicate permutations (DFS)

중복순열 코드질문

Written on

·

261

0

안녕하세요, 강의 잘 듣고 있습니다!

혼자서 코드를 짜볼때 저는 아래와 같이 짰는데 다시 재귀로 돌아가지 못하고 1 1 만 출력하고 종료해 버리더라구요. 소스에서 어디가 문제인지 정확히 찾을 수 없어, 뭐가 문제인지 문의드립니다.

def DFS(L):

    global cnt

    if L==m+1:

        for x in a:

            print(x, end=' ')

        print()

        cnt+=1

    else:

        for i in range(1, n+1):

            a.append(i)

            DFS(L+1)

            a.pop(-1)

    

if __name__=="__main__":

    n, m=map(int, input().split())

    a=list()

    cnt=0

    DFS(0) 

    print(cnt)

python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

if L==m: 로 바꾸세요. 그 외에는 정상입니다.

modestajihyelee0969's profile image
modestajihyelee0969

asked

Ask a question