정답 코드
from itertools import permutations
n = int(input())
iter = [i for i in range(1, n+1)]
for i in permutations(iter, len(iter)) :
ans = i
print(' '.join(map(str, ans)))
N=int(input())
def permutation(n,r,temp=[]):
if r == 0:
return print(*temp)
else:
for i in range(1,n+1):
if i not in temp:
temp.append(i)
permutation(n,r-1,temp)
temp.remove(i)
permutation(N,N)
'코딩 테스트 > 백준' 카테고리의 다른 글
[Python] 백준 3040 백설 공주와 일곱 난쟁이 (0) | 2025.02.11 |
---|---|
[Python] 백준 10989 수 정렬하기 3 (0) | 2025.02.10 |
[Python] 백준 11729 하노이 탑 이동 순서 (0) | 2025.02.10 |
[Python] 백준 2577 숫자의 개수 (0) | 2025.02.07 |
[Python] 백준 2667 단지번호붙이기 (0) | 2025.02.07 |