728x90
반응형
문제 출처: https://www.acmicpc.net/problem/15666
15666번: N과 M (12)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
풀이:
import sys
sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r')
n,m = map(int,input().split())
x = sorted(list(map(int,input().split())))
result = []
def bt():
if m == len(result):
print(*result)
return
now = 0
for i in range(n):
if now != x[i]:
if any(x[i] < num for num in result):
continue
result.append(x[i])
now = x[i]
bt()
result.pop()
bt()
if any(x[i] < num for num in result):
continue
이 전 문제에서 위에 두줄 추가하면 된다.
반응형
댓글