https://www.acmicpc.net/problem/15650
15650번: N과 M (2)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
백준 15650 'N과 M (2)' 문제입니다.
기본 'N과 M' 문제에서
if i not in s:
if not s or s[-1] < i:
위 조건문을 추가해주었습니다.
n ,m = map(int, input().split())
s = []
def dfs():
if len(s) == m:
print(" ".join(map(str, s)))
return
for i in range(1, n+1):
if i not in s:
if not s or s[-1] < i:
s.append(i)
dfs()
s.pop()
dfs()
'백준 알고리즘' 카테고리의 다른 글
파이썬) 백준 알고리즘 | 15664번 : N과 M (10) (0) | 2022.03.03 |
---|---|
파이썬) 백준 알고리즘 | 15663번 : N과 M (9) (0) | 2022.03.03 |
파이썬) 백준 알고리즘 | 15657번 : N과 M (8) (0) | 2022.03.03 |
파이썬) 백준 알고리즘 | 15655번 : N과 M (6) (0) | 2022.03.03 |
파이썬) 백준 알고리즘 | 15652번 : N과 M (4) (0) | 2022.03.03 |
댓글