Algorithm/Algorithm_Theory
브루트포스(BruteForce)
yunajoe
2022. 10. 10. 11:36
가능한 모든 경우의 수를 구해보는 것(it is just like iterating every possibility available to solve that problem)
예를 들어, 4자리 비밀번호를 알아내려고 할 때(비밀번호는 0-9까지) 0001,0002,....9999까지 모든 경우의 수를 구하는 것을 말한다.
실습)
# left_cards에서 하나, right_cards에서 하나를 뽑아 두 카드의 곱이 가장 클 때를 구하기
def max_product(left_cards, right_cards):
# 코드를 작성하세요.
max_number = 0
for i in range(len(left_cards)):
for j in range(len(right_cards)):
if left_cards[i] * right_cards[j] > max_number:
max_number = left_cards[i] * right_cards[j]
return max_number