Skip to content

Commit c8487a3

Browse files
committed
백준 15663번 N과 M (9)
문제 링크: https://www.acmicpc.net/problem/15663
1 parent 11e702b commit c8487a3

File tree

8 files changed

+79
-0
lines changed

8 files changed

+79
-0
lines changed

백준 15663번 N과 M (9)/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
from typing import List, Set
3+
4+
5+
def solve():
6+
N, M = map(int, sys.stdin.readline().strip().split(' '))
7+
dts: List[int] = list(map(int, sys.stdin.readline().strip().split(' ')))
8+
visited: List[bool] = [False for _ in range(len(dts))]
9+
ans: Set = set()
10+
11+
mycomb(dts, ans, [], 0, M, visited)
12+
13+
ans: List[int] = list(ans)
14+
ans.sort()
15+
for item in ans:
16+
print(' '.join(map(str, item)))
17+
18+
19+
def mycomb(dts: List[int], ans: Set, path: List[int], depth, depth_max, visited):
20+
if depth == depth_max:
21+
ans.add(tuple(path))
22+
return
23+
24+
for idx in range(len(dts)):
25+
if visited[idx]:
26+
continue
27+
28+
visited[idx] = True
29+
mycomb(dts, ans, path + [dts[idx]], depth + 1, depth_max, visited)
30+
visited[idx] = False
31+
32+
33+
if __name__ == '__main__':
34+
solve()

백준 15663번 N과 M (9)/test1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3 1
2+
4 4 2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2
2+
4

백준 15663번 N과 M (9)/test2.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
4 2
2+
9 7 9 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1 7
2+
1 9
3+
7 1
4+
7 9
5+
9 1
6+
9 7
7+
9 9

백준 15663번 N과 M (9)/test3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
4 4
2+
1 1 1 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 1 1 1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
from pathlib import Path
3+
from unittest import TestCase
4+
from main import solve
5+
6+
7+
class Test(TestCase):
8+
def my_solve(self, testcase_input):
9+
sys.stdin = open(testcase_input, 'r')
10+
stdout = sys.stdout
11+
sys.stdout = open('stdout.txt', 'w')
12+
solve()
13+
sys.stdout.close()
14+
sys.stdout = stdout
15+
16+
def test_solve(self, testcase_number: str):
17+
self.my_solve('test' + testcase_number + '.txt')
18+
self.assertEqual(
19+
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
20+
Path('stdout.txt').read_text().strip())
21+
22+
def test1_solve(self):
23+
self.test_solve('1')
24+
25+
def test2_solve(self):
26+
self.test_solve('2')
27+
28+
def test3_solve(self):
29+
self.test_solve('3')

0 commit comments

Comments
 (0)