알고리즘/Baekjoon
[CodingTest] 백준 #15652 N과 M (4) 파이썬 / combinations_with_replacement
Happyoon ~
2021. 11. 27. 04:07
728x90
반응형
https://www.acmicpc.net/problem/15652
15652번: N과 M (4)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
내 풀이
from itertools import combinations_with_replacement as cr
n,m = map(int,input().split())
lst = [i+1 for i in range(n)]
result = list(cr(lst,m))
for item in result:
print(*item)
바로 이전 게시물에서 공부한 중복 조합으로 풀어주었다.
중복 조합 관련 설명은 아래에서 ↓↓
https://live-for-myself.tistory.com/155
[CodingTest] 파이썬 백준 #15651 N과 M (3) / 중복순열 product, 중복조합 combinations_with_replacement
https://www.acmicpc.net/problem/15651 15651번: N과 M (3) 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다.
live-for-myself.tistory.com
다른 사람들도 다 중복조합을 이용해서 푼 것 같다.
반응형