웹찢남

[백준 15649 N과 M 문제] PYTHON 본문

백준 Algorithm

[백준 15649 N과 M 문제] PYTHON

harry595 2021. 8. 10. 17:24

 

itertools의 permutations만 안다면 쉽게 풀 수 있는 문제다.

(permutations는 a = [1,2,3] pe= permutations(a,2) 이면 pe는 [(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)] 이다 (순열))

 

# https://www.acmicpc.net/problem/15649
from itertools import permutations

A, B = map(int, input().split())

numlist = [tmp for tmp in range(1, A+1)]
permute = permutations(numlist, B)
for perm in list(permute):
    for per in perm:
        print(per, end=' ')
    print()
Comments