美文网首页
Lintcode437 Copy Books solution

Lintcode437 Copy Books solution

作者: 程风破浪会有时 | 来源:发表于2018-02-28 10:31 被阅读0次

    【题目描述】

    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

          本文链接:https://www.haomeiwen.com/subject/jwvngxtx.html