반응형
Notice
Recent Posts
Recent Comments
Link
동캄의 코딩도장
백준 10974 [모든 순열] 파이썬 본문
반응형
#10974
n=int(input())
s=[]
def dfs():
if len(s)==n:
print(' '.join(map(str,s)))
return
for i in range(1,n+1):
if i in s:
continue
s.append(i)
dfs()
s.pop()
dfs()
1부터 n까지 dfs문을 돌려서 순열을 출력하였다.
itertools.permutations() 라는 라이브러리 함수를 사용하면 더욱 쉽게 풀 수 있을거같다.
반응형
'코테 > BOJ' 카테고리의 다른 글
백준 9251 [LCS] 파이썬 (0) | 2021.12.14 |
---|---|
백준 6603 [로또] 파이썬 (0) | 2021.12.02 |
백준 15657 [N과M (8)] 파이썬 (0) | 2021.12.02 |
백준 15656 [N과M (7)] 파이썬 (0) | 2021.12.02 |
백준 15655 [N과 M (6)] 파이썬 (0) | 2021.12.02 |