# n 입력
n = int(input())
# ppl_list 입력
ppl_list = list(map(int, input().split()))
# 함수들
# search(k)
def search(k):
# dist 설정
dist = 0
# 거리구하기
for idx in range(n):
dist += abs(idx - k) * ppl_list[idx]
# 반환
return dist
# 설계
# 최소 거리
import sys
short_cut = sys.maxsize
# 완전 탐색
for i in range(n):
# 탐색
curr_dist = search(i)
# 최솟값 갱신
short_cut = min(short_cut, curr_dist)
# 출력
print(short_cut)'Algorithm(CodeTree, Python) > 완전탐색1' 카테고리의 다른 글
| [코드트리 자리 수 단위로 완전탐색] 마라톤 중간에 택시타기 2 python (0) | 2022.11.14 |
|---|---|
| [코드트리 자리 수 단위로 완전탐색] 일렬로 서있는 소 2 python (0) | 2022.11.10 |
| [코드트리 자리 수 단위로 완전탐색] 괄호 쌍 만들어주기 3 python (0) | 2022.11.08 |
| [코드트리 자리 수 단위로 완전탐색] 이상한 진수 2 python (0) | 2022.11.07 |
| [코드트리 자리 수 단위로 완전탐색] 괄호 쌍 만들어주기 2 python (0) | 2022.11.03 |