Baekjoon Case

[백준 #15652] N과 M(4) - 파이썬(python)

Scarlett_C 2021. 8. 14. 12:30
728x90

https://www.acmicpc.net/problem/15652

비내림차순이라고 하는 이유가 같은 수가 있어서 그런거였구나..

from itertools import combinations_with_replacement

N,M=map(int,input().split())
numlist=map(str,range(1,N+1))
setlist=list(combinations_with_replacement(numlist,M))
print('\n'.join(list(map(' '.join,setlist))))

itertools 라이브러리에서 조합과 순열 관련한 함수들을 모조리 다 써보는 문제였군.

이 라이브러리를 몰랐다면,, 아마 답답함에 몸부림 쳤을 듯 싶다.

 

이번에는 combinations_with_replace(arr,n) 함수를 써서 풀었다.

 

아주 유익한 라이브러리인 것 같다.

728x90