[Python | 파이썬] 백준 파일 합치기 11066
참고한 블로그 : https://inspirit941.tistory.com/254

더보기
# import sys
INF = int(1e9)
# input = sys.stdin.readline
tc = int(input().rstrip())
for t in range(tc):
n = int(input().rstrip())
arr = list(map(int, input().rstrip().split()))
cumsum = {-1:0}
for i in range(len(arr)):
cumsum[i] = cumsum[i-1] + arr[i]
dp = [[0 for _ in range(len(arr))] for _ in range(len(arr))]
for gap in range(1, len(arr)):
for start in range(len(arr)):
end = start + gap
if end == len(arr):
break
dp[start][end] = INF
for i in range(start, end):
dp[start][end] = min(dp[start][end], dp[start][i] + dp[i+1][end] + cumsum[end] - cumsum[start-1])
print(dp[0][-1])
https://www.acmicpc.net/problem/11066
11066번: 파일 합치기
소설가인 김대전은 소설을 여러 장(chapter)으로 나누어 쓰는데, 각 장은 각각 다른 파일에 저장하곤 한다. 소설의 모든 장을 쓰고 나서는 각 장이 쓰여진 파일을 합쳐서 최종적으로 소설의 완성본
www.acmicpc.net
'Problem Solving > BOJ - Python' 카테고리의 다른 글
[Python | 파이썬] 백준 17142 연구소3 (0) | 2021.06.05 |
---|---|
[Python | 파이썬] 백준 계단 오르기 2579 (0) | 2021.05.27 |
[Python | 파이썬] 백준 10844 쉬운 계단 수 (0) | 2021.05.27 |
[Python | 파이썬] 백준 11053 가장 긴 증가하는 부분 수열 (0) | 2021.05.27 |
[Python | 파이썬] 백준 11054 가장 긴 바이토닉 부분 수열 (0) | 2021.05.27 |