1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 | from collections import Counter as ctr
n, m = map(int, input().split())
series = list(map(int, input().split()))
series = list(ctr(series).items())
series.sort()
n = len(series)
nums, cnt = map(list, zip(*series))
answer = [0]*m
result = []
# 중복불허, 중복된 N 수열[9,7,9,1] 에서 M 출력, 비내림차순
def recur6(n, m, idx):
if idx == m:
print(' '.join(map(str, answer)))
return
for i in range(n):
if idx > 0:
if answer[idx-1] <= nums[i]:
answer[idx] = nums[i]
recur6(n, m, idx+1)
else:
answer[idx] = nums[i]
recur6(n, m, idx+1)
recur6(n, m, 0)
# # 중복불허, 중복된 N 수열[9,7,9,1] 에서 M 출력, 순서고려
# def recur5(n, m, idx):
# if idx == m:
# print(' '.join(map(str, answer)))
# return
#
# for i in range(n):
# if cnt[i] > 0:
# cnt[i] -= 1
# answer[idx] = nums[i]
# recur5(n, m, idx+1)
# cnt[i] += 1
#
# recur5(n, m, 0)
# # 중복허용한 N개 수중 M개 고른 비내림차순 수열
# def recur4(n, m, idx):
# if idx == m:
# print(' '.join(map(str, answer)))
# return
#
# for i in range(n):
# if idx > 0:
# if answer[idx-1] <= series[i]:
# answer[idx] = series[i]
# recur4(n, m, idx + 1)
# else:
# answer[idx] = series[i]
# recur4(n, m, idx+1)
#
# recur4(n, m, 0)
# # 중복허용한 N개 수중 M개 고른 수열
# def recur3(n, m, idx):
# if idx == m:
# print(' '.join(map(str, answer)))
# return
#
# for i in range(n):
# answer[idx] = series[i]
# recur3(n, m, idx+1)
#
# recur3(n, m, 0)
# # 중복불허한 N개 수중 M개 고른 오름차순 수열, 순서 고려 함
# def recur2(n, m, idx, start):
# if idx == m:
# print(' '.join(map(str, answer)))
# return
#
# for i in range(start, n):
# if check[i]:
# continue
# check[i] = True
# answer[idx] = series[i]
# recur2(n, m, idx+1, i+1)
# check[i] = False
#
# recur2(n, m, 0, 0)
# # 중복불허한 N개 수중 M개 고른 수열, 순서 고려 안함
# def recur1(n, m, idx):
# if idx == m:
# print(' '.join(map(str, answer)))
# return
#
# for i in range(n):
# if check[i]:
# continue
# check[i] = True
# answer[idx] = series[i]
# recur1(n, m, idx+1)
# check[i] = False
#
# recur1(n, m, 0)
|
댓글
댓글 쓰기