728x90
< 처음 풀 때 >
조합과 중복이 섞여 있어서 까다로웠다. 함수를 만들어서 배열을 이용한 방법으로 해결하려고 했지만 시간 초과가 나왔고, combination_with_replacement 라는 신기한 중복 조합 함수를 알게 되었다.
< 다시 풀 때 >
combination_with_replacement 를 이용해서 어렵지 않게 풀 수 있었다.
import sys
import math
from itertools import product
from itertools import combinations_with_replacement
a,b = map(int, sys.stdin.readline().split(" "))
k = [ ]
for i in range(1,a+1):
k.append(i)
q = list(combinations_with_replacement(k,b))
for i in q:
print(*i)728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 18870 좌표 압축 (0) | 2022.08.02 |
|---|---|
| [파이썬] 백준 2004 조합 0의 개수 (0) | 2022.08.02 |
| [파이썬] 백준 2981 검문 (0) | 2022.08.02 |
| [파이썬] 백준 15651 N과 M (3) (0) | 2022.08.01 |
| [파이썬] 백준 1004 어린 왕자 (0) | 2022.08.01 |