순열과 조합

#순열과 조합 #브루트포스 알고리즘

파이썬에서의 순열과 조합

파이썬 기본 라이브러리 사용법 출처 : https://heytech.tistory.com/78 순열, 조합 공식 참고 : https://coding-factory.tistory.com/606

#1 순열

from itertools import permutations 
dataset = ['A', 'B', 'C'] 
res = list(permutations(dataset, 3))
print(f"모든 조합: {res}") 
# [('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), 
# ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]

#2 조합

from itertools import combinations 
dataset = ['A', 'B', 'C'] 
res = list(combinations(dataset, 2)) 
print(f"모든 경우: {res}") 
# [('A', 'B'), ('A', 'C'), ('B', 'C')]

#3 중복 순열

from itertools import product 
dataset = ['A', 'B', 'C'] 
res = list(product(dataset, repeat = 2)) 
print(f"모든 경우: {res}") 
# [('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'B'), ('B', 'C'), ('C', 'A'), ('C', 'B'), ('C', 'C')]

#4 중복 조합


백준 2798번 : 블랙잭

1. 중첩 반복문 풀이

2. 파이썬 기본 라이브러리 사용 풀이

중복순열

백준 7490번 : 0 만들기

1. 재귀함수 풀이

2. 파이썬 라이브러리 사용 풀이

Last updated