저번에 풀었던 15649문제에서 코드를 살짝만 수정하면 쉽게 구할수 있다.
조건은 뒤에 수열이 반드시 오름차순이어야하며 중복을 포함하지 않는다.
코드의 중복이 살짝 있지만 애교로 넘어가자
n,m = map(int,input().split())
Map=[i for i in range(1,n+1)]
def back(tlist, n,m):
if m == 0:
for i in tlist:
print(Map[i],end=' ')
print()
return
for i in range(n):
if len(tlist) == 0:
tlist.append(i)
back(tlist,n,m-1)
tlist.pop()
else:
if i > tlist[-1]:
tlist.append(i)
back(tlist,n,m-1)
tlist.pop()
back([],n,m)
'알고리즘' 카테고리의 다른 글
백준 14888 풀이 (재귀함수, 백트래킹, 연산자 끼워넣기) (0) | 2021.02.16 |
---|---|
백준 9663 풀이 (백트래킹, 재귀함수) (0) | 2021.02.16 |
백준 15649 풀이 (재귀함수, 백트래킹) (0) | 2021.02.15 |
백준 11651 풀이 (sort, 여러 인자 정렬하기) (0) | 2021.02.14 |
백준 2108 풀이 (python, collections, Counter) (0) | 2021.02.13 |