코테용 문제풀이/백준
다음 순열 풀이
문제 링크: https://www.acmicpc.net/problem/10972 백준 알고리즘 기초 2/2 520에서 1번째 - 10972번 다음 순열을 풀어보았다. 풀이: next permutation을 구하는 문제이다. 파이썬은 https://dallae7.tistory.com/155 를 참고했다. C++ Python N=int(input()) arr=list(map(int, input().split())) def next_permutation(): i=N-1 while(i>0 and arr[i-1]>=arr[i]): i-=1 if i==0: return False j=N-1 while(arr[i-1]>=arr[j]): j-=1 arr[i-1], arr[j] = arr[j], arr[i-1] k=N-..
N과 M (12) 풀이
문제 링크: https://www.acmicpc.net/problem/15666 백준 알고리즘 기초 2/2 510에서 12번째 - 15666번 N과 M (12)를 풀어보았다. 풀이: 파이썬의 경우 combinations_with_replacement을 쓰고, set을 써서 중복을 제거했다. C++ Python from itertools import combinations_with_replacement n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=list(set(combinations_with_replacement(arr,m))) res.sort() for i in res: for j in i: print(j,..
N과 M (11) 풀이
문제 링크: https://www.acmicpc.net/problem/15665 백준 알고리즘 기초 2/2 510에서 11번째 - 15665번 N과 M (11)를 풀어보았다. 풀이: 파이썬의 경우 product을 쓰고, set을 써서 중복을 제거했다. C++ Python from itertools import product n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=list(set(product(arr,repeat=m))) res.sort() for i in res: for j in i: print(j,end=' ') print() Java
N과 M (10) 풀이
문제 링크: https://www.acmicpc.net/problem/15664 백준 알고리즘 기초 2/2 510에서 10번째 - 15664번 N과 M (10)를 풀어보았다. 풀이: 파이썬의 경우 combinations을 쓰고, set을 써서 중복을 제거했다. C++ Python from itertools import combinations n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=list(set(combinations(arr,m))) res.sort() for i in res: for j in i: print(j,end=' ') print() Java
N과 M (9) 풀이
문제 링크: https://www.acmicpc.net/problem/15663 백준 알고리즘 기초 2/2 510에서 9번째 - 15663번 N과 M (9)를 풀어보았다. 풀이: 파이썬의 경우 permutations을 쓰고, set을 써서 중복을 제거했다. C++ Python from itertools import permutations n,m=map(int,input().split()) arr=list(map(int,input().split())) res=list(set(permutations(arr,m))) res.sort() for i in res: for j in i: print(j,end=' ') print() Java
N과 M (8) 풀이
문제 링크: https://www.acmicpc.net/problem/15657 백준 알고리즘 기초 2/2 510에서 8번째 - 15657번 N과 M (8)를 풀어보았다. 풀이: 파이썬의 경우 combinations_with_replacement을 이용했다. C++ Python from itertools import combinations_with_replacement n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=combinations_with_replacement(arr,m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (7) 풀이
문제 링크: https://www.acmicpc.net/problem/15656 백준 알고리즘 기초 2/2 510에서 7번째 - 15656번 N과 M (7)를 풀어보았다. 풀이: 파이썬의 경우 product을 이용했다. C++ Python from itertools import product n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=product(arr,repeat=m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (6) 풀이
문제 링크: https://www.acmicpc.net/problem/15655 백준 알고리즘 기초 2/2 510에서 6번째 - 15655번 N과 M (6)를 풀어보았다. 풀이: 파이썬의 경우 combinations을 이용했다. C++ Python from itertools import combinations n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=combinations(arr,m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (5) 풀이
문제 링크: https://www.acmicpc.net/problem/15654 백준 알고리즘 기초 2/2 510에서 5번째 - 15654번 N과 M (5)를 풀어보았다. 풀이: 파이썬의 경우 permutations을 이용했다. C++ Python from itertools import permutations n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=permutations(arr,m) for i in res: for j in i: print(j,end=' ') print() Java
N과 M (4) 풀이
문제 링크: https://www.acmicpc.net/problem/15652 백준 알고리즘 기초 2/2 510에서 4번째 - 15652번 N과 M (4)를 풀어보았다. 풀이: 파이썬의 경우 combinations_with_replacement을 이용했다. C++ Python from itertools import combinations_with_replacement n,m=map(int,input().split()) arr=[i+1 for i in range(n)] res=combinations_with_replacement(arr,m) for i in res: for j in i: print(j,end=' ') print() Java