📌문제
https://www.acmicpc.net/problem/15649
🎖️난이도
✔️풀이
# sol1) back tracking (recursion)
N, M = map(int, input().split())
result = list()
def func():
if len(result) == M:
print(' '.join(map(str, result)))
return
for i in range(1, N+1):
if i not in result:
result.append(i)
func()
result.pop()
func()
# sol2) itertools - permutations (순열)
from itertools import permutations
n, m = map(int, input().split())
for i in permutations(range(1, n+1), m):
# int로 출력
for j in i:
print(j, end=' ')
print()
# sol3
from itertools import permutations
n, m = map(int, input().split())
for i in permutations(range(1, n+1), m):
# str로 출력
print(' '.join(map(str, i)))
'[ 알고리즘 ] > Back Tracking' 카테고리의 다른 글
[백준] 9663. N-Queen (0) | 2022.06.30 |
---|---|
[백준] 15651. N과 M (3) (0) | 2022.06.30 |
[백준] 15650. N과 M (2) (0) | 2022.06.30 |