2021-02-07
문제 : https://www.acmicpc.net/problem/15652
1. 1부터 N까지 자연수 중에서 M개를 고른 수열
2. 같은 수를 여러 번 골라도 된다.
3. 고른 수열은 비내림차순이어야 한다.
- 길이가 K인 수열 A가 A1 ≤ A2 ≤ ... ≤ AK-1 ≤ AK를 만족하면, 비내림차순이라고 한다.
15651번에서 idx를 추가해서 3번 조건 만족시킴
[소스코드]
https://github.com/jisun1125/algorithm-problem-solving/blob/main/baekjoon/no_15652.py
n, m = map(int, input().split())
k = []
def solve(depth, idx, n, m):
if depth == m:
print(' '.join(map(str, k)))
return
for i in range(idx, n):
k.append(i+1)
solve(depth+1, i, n, m)
k.pop()
solve(0, 0, n, m)
'PS > 백준' 카테고리의 다른 글
[백준/Python(파이썬)] 15655 N과 M (6) (0) | 2021.02.14 |
---|---|
[백준/Python(파이썬)] 15654 N과 M (5) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15651 N과 M (3) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15650 N과 M (2) (0) | 2021.02.14 |
[백준/Python(파이썬)] 15649 N과 M (1) (0) | 2021.02.14 |