-
Notifications
You must be signed in to change notification settings - Fork 0
/
15663.py
42 lines (35 loc) ยท 1.41 KB
/
15663.py
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
# -*- coding: utf-8 -*-
# ์์ด ์์์ ๊ธธ์ด N, ์ถ๋ ฅํ ์์ด์ ๊ธธ์ด M
# ์กฐ๊ฑด: ์์ด์ ์ฌ์ ์์ผ๋ก ์ถ๋ ฅ
# ์ค๋ณต๋ ์์ด์ ์ถ๋ ฅํ์ง ์์
# ํ์ด: ์์ด์ ์ฌ์ ์์ผ๋ก ์ถ๋ ฅํ๊ธฐ ์ํด ์์ด ์์๋ฅผ ์ค๋ฆ์ฐจ์์ผ๋ก ์ ๋ ฌ
# ๊ฐ์ ์์์ธ์ง ํ์ธํ check ๋ฆฌ์คํธ์ ๊ฐ์ ์์ด์ธ์ง ํ์ธํ check_ans ๋ฆฌ์คํธ ์์ฑ
# ์์ด(ans)์ ๊ธธ์ด๊ฐ M์ผ ๊ฒฝ์ฐ ans๋ฅผ ๋ฌธ์์ด๋ก ๋ฌถ์ด ํด๋น ๋ฌธ์์ด์ด check_ans ๋ฆฌ์คํธ์ ์กด์ฌํ๋์ง ํ์ธ
# ์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ ์ถ๋ ฅ ํ check_ans์ ์ถ๊ฐ
# list_์ ๋ชจ๋ ์์๋ฅผ ํ์ธํ๋ฉฐ ํ์ฌ ์์ด(ans)๋ฅผ ์ด๋ฃจ๋ ์์๊ฐ ์ค๋ณต๋์ง ์๋๋ก ์ค๋ณต ์ฒดํฌ
# ์ค๋ณตํ์ง ์๋ ๊ฒฝ์ฐ ์์ด(ans)์ list_[idx]์ถ๊ฐ + check ๋ฆฌ์คํธ์ idx ์ถ๊ฐ
import sys
N, M = map(int, sys.stdin.readline().split())
list_ = list(map(int, sys.stdin.readline().split()))
list_.sort()
ans = []
check = []
check_ans = set()
check_ans_len = 0
def dfs():
global ans, list_, N, M, check_ans, check_ans_len
if len(ans) == M:
tmp = ' '.join(ans)
check_ans.add(tmp)
if check_ans_len != len(check_ans):
print(*ans)
check_ans_len += 1
return
for idx in range(0, N):
if idx in check: continue
ans.append(str(list_[idx]))
check.append(idx)
dfs()
ans.pop()
check.pop()
dfs()