조합

파이썬

[파이썬 ] itertools 사용법

순열을 이용해 완전탐색 문제를 풀 때, dfs와 같은 재귀를 사용해야만 하는 경우도 있다. 그러나 재귀는 overflow를 유도하는 가장 쉬운 방법이기 때문에 항상 사용할 때 유의해야 한다. 우리는 이제 순열 조합을 이용한 문제를 코드 한 줄로 풀 수 있다. combinations() # 조합 combinations_with_replacement() # 중복조합 product() # 데카르트 곱 permutations() # 순열 combinations(iterable, r) iterable에서 원소 개수가 r개인 조합 뽑기 from itertools import combinations if __name__ == '__main__': iterator = [1, 2, 3, 4] for i in combin..

알고리즘/자료구조

dfs로 순열, 조합 구하기

2022.02.08 아직까진 조금 어렵다.. 이해가 팍 안되는 느낌 2022.02.14 중복순열 추가 dfs로 순열 구하기 void dfs(int cnt) { if (cnt == m) { for (int i = 0; i < m; i++) { cout m; dfs(0); return 0; } dfs로 조합 구하기 void dfs(int num, int cnt) { if (cnt == m) { for (int i = 0; i < m; i++) cout m; dfs(1,0); return 0; } dfs로 중복조합 구하기 #include using namespace std; int n, m; int arr[9]; bool visited[9]; void dfs(int num, int cnt) { if (cnt ..

beomseok99
'조합' 태그의 글 목록