-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path03.py
48 lines (41 loc) · 974 Bytes
/
03.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
43
44
45
46
47
48
# 자연수 N과 M이 주어졌을 때, 1부터 N까지 자연수 중에서 M개를 고른 수열
# 중복 포함
# 나의 정답
N, length = map(int, input().split())
count = 1
nums = [[i] for i in range(1, N+1)]
while count < length:
prev_nums = nums
new_nums = []
for num in prev_nums:
for i in range(1, N+1):
new_nums.append(num + [i])
nums = new_nums
count += 1
for num in nums:
print(' '.join(map(str, num)))
# =================================================================
# 다른 사람의 풀이
import itertools
N,M = map(int,input().split())
list1 = list(map(str,range(1,N+1)))
print("\n".join(list(map(" ".join,itertools.product(list1,repeat=M)))))
# =================================================================
# 4 2 (input)
# 1 1 (output)
# 1 2
# 1 3
# 1 4
# 2 1
# 2 2
# 2 3
# 2 4
# 3 1
# 3 2
# 3 3
# 3 4
# 4 1
# 4 2
# 4 3
# 4 4
# =================================================================