Lintcode437 Copy Books solution 题解

【题目描述】

Given n books and the ith book has A[i] pages. You are given k people to copy the n books.

n books list in a row and each person can claim a continous range of the n books. For example one copier can copy the books from ith to jth continously, but he can not copy the 1st book, 2nd book and 4th book (without 3rd book).

They start copying books at the same time and they all cost 1 minute to copy 1 page of a book. What's the best strategy to assign books so that the slowest copier can finish at earliest time?

给出一个数组A包含n个元素,表示n本书以及各自的页数。现在有个k个人复印书籍,每个人只能复印连续一段编号的书,比如A[1],A[2]由第一个人复印,但是不能A[1],A[3]由第一个人复印,求最少需要的时间复印所有书。

【题目链接】

www.lintcode.com/en/problem/copy-books/

【题目解析】

区间动态规划

state dp[i][k] - 前i本书交给k个人copy的最小花费

function

`dp[i][k] = max(dp[j][k-1], cost[j+1][i]) (j < i)

init

dp[i][1] = cost[1][i]

result

dp[n][k]

注意:建matrix时多建一个,将0-based index转换为1开始 -当k大于n时,所需的时间即为最大的那本书的长度

【参考答案】

www.jiuzhang.com/solutions/copy-books/

你可能感兴趣的:(Lintcode437 Copy Books solution 题解)