프로그래밍/자료구조&알고리즘

알고리즘 문제 유형 - 완전탐색(permutation, combination)

O'bin 2024. 2. 14. 11:48

브루트 포스(Brute Force)

시간 제한에 걸리지 않을 것 같거나, 풀이 방법이 바로 떠오르지 않는 문제의 경우

완전탐색으로 풀이를 시작하는 것도 방법

 

순열(permutation)

모든 경우의 수를 순서대로 살펴볼 때 용이

1
2
3
4
5
6
from itertools import permutations
 
= [0,1,2,3]
 
for i in permutations(v,4):
    print(i)
cs

 

 

 

 

조합(combination)

배열에서 특정 n개를 뽑아야 하는 경우(순서 상관 x)

1
2
3
4
5
6
from itertools import combinations
 
= [0,1,2,3]
 
for i in combinations(v,2):
    print(i)
cs