PS/BOJ
[BOJ] N과 M (11) 15665
RUBY_루비
2020. 7. 1. 09:48
출처:: https://www.acmicpc.net/problem/15665
1. 문제 이해 및 해결과정
-중복순열
2. 풀이방법
1. join으로 출력하기
#N과 M (11)
#https://www.acmicpc.net/problem/15665
import sys
sys.stdin = open("input.txt","r")
def DFS(L):
if L==m:
#for x in res:
#print(x,end=' ')
print(' '.join(map(str,res)))
#print()
else:
for i in range(len(a)):
res[L]=a[i]
DFS(L+1)
if __name__=="__main__":
n, m = map(int, input().split())
a = sorted(set(list(map(int, input().split()))))
res=[0]*m
DFS(0)
2. 반복문으로 출력하기
#N과 M (11)
#https://www.acmicpc.net/problem/15665
import sys
sys.stdin = open("input.txt","r")
def DFS(L):
if L==m:
for x in res:
print(x,end=' ')
print()
else:
for i in range(len(a)):
res[L]=a[i]
DFS(L+1)
if __name__=="__main__":
n, m = map(int, input().split())
a = sorted(set(list(map(int, input().split()))))
res=[0]*m
DFS(0)
3. 오답원인
4. 알게된 점
*1 7 9 9 에서 1 7 9 만 중복없이 만드는 방법
a = sorted(set(list(map(int, input().split()))))