728x90
반응형
브루트포스 알고리즘 문제이다. combinations를 사용해서 모든 조합을 다 확인하는 방식으로 최솟값을 찾았다.
from itertools import combinations
N = int(input())
arr = [list(map(int, input().split(" "))) for _ in range(N)]
coms = [combinations(arr, i) for i in range(1, N+1)]
ans = 1000000000
for com in coms:
for t in com:
S, B = 1, 0
for s, b in t:
S *= s
B += b
ans = min(ans, abs(S-B))
print(ans)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 2599번 수열(python) (0) | 2021.03.07 |
---|---|
백준 알고리즘 6588번 골드바흐의 추측(python) (0) | 2021.03.07 |
백준 알고리즘 1254번 팰린드롬 만들기(python) (0) | 2021.03.07 |
백준 알고리즘 7785번 회사에 있는 사람(python) (0) | 2021.03.07 |
백준 알고리즘 1918번 후위 표기식(python) (0) | 2021.03.07 |