Skip to content

Commit 4216ef4

Browse files
committed
백준 15666번 N과 M (12)
문제 링크: https://www.acmicpc.net/problem/15666
1 parent c8487a3 commit 4216ef4

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed

백준 15666번 N과 M (12)/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
from typing import List, Tuple, 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+
ans: Set[Tuple] = set()
9+
10+
mycomb(dts, 0, M, ans, [])
11+
12+
ans: List[Tuple] = list(ans)
13+
ans.sort()
14+
15+
for item in ans:
16+
print(' '.join(map(str, item)))
17+
18+
19+
def mycomb(dts: List[int], depth: int, depth_max: int, ans: Set[Tuple], path: List[int]):
20+
if depth == depth_max:
21+
path.sort()
22+
ans.add(tuple(path))
23+
return
24+
25+
for idx in range(len(dts)):
26+
mycomb(dts, depth + 1, depth_max, ans, path + [dts[idx]])
27+
28+
29+
if __name__ == '__main__':
30+
solve()

백준 15666번 N과 M (12)/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

백준 15666번 N과 M (12)/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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 1
2+
1 7
3+
1 9
4+
7 7
5+
7 9
6+
9 9

백준 15666번 N과 M (12)/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 2 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1 1 1 1
2+
1 1 1 2
3+
1 1 2 2
4+
1 2 2 2
5+
2 2 2 2
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)