思路:

dp[i]表示摆放好前i本书所需要的最小代价。

实现:

 class Solution
{
public:
int minHeightShelves(vector<vector<int>>& books, int shelf_width)
{
int n = books.size();
vector<int> dp(n + , );
dp[] = ; dp[] = books[][];
for (int i = ; i <= n; i++)
{
dp[i] = dp[i - ] + books[i - ][];
int sum = books[i - ][], maxn = books[i - ][];
for (int j = i - ; j >= ; j--)
{
if (sum + books[j - ][] > shelf_width) break;
maxn = max(maxn, books[j - ][]);
dp[i] = min(dp[i], dp[j - ] + maxn);
sum += books[j - ][];
}
}
return dp[n];
}
}

leetcode1105 Filling Bookcase Shelves的更多相关文章

  1. LeetCode 1105. Filling Bookcase Shelves

    原题链接在这里:https://leetcode.com/problems/filling-bookcase-shelves/ 题目: We have a sequence of books: the ...

  2. 【leetcode】1105. Filling Bookcase Shelves

    题目如下: We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1]. W ...

  3. 【Codeforces-707D】Persistent Bookcase DFS + 线段树

    D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...

  4. Codeforces Round #368 (Div. 2) D. Persistent Bookcase

    Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...

  5. Persistent Bookcase

    Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  6. Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力

    D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...

  7. codeforces 707D:Persistent Bookcase

    Description Recently in school Alina has learned what are the persistent data structures: they are d ...

  8. codeforces 707D D. Persistent Bookcase(dfs)

    题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input ...

  9. Codeforces-707D:Persistent Bookcase (离线处理特殊的可持久化问题&&Bitset)

    Recently in school Alina has learned what are the persistent data structures: they are data structur ...

随机推荐

  1. HTML 文字垂直剧中

    HTML 有个使文字垂直剧中的代码   line-height:     line-height:使用时  总高多少 后边就输入多少PX 剧中前展示 剧中后展示

  2. 2G以上的大文件如何上传

    无法上传大文件是因为php.ini配置有限制了,这样限制了用户默认最大为2MB了,超过了就不能上传了,如果你确实要上传我们可以按下面方法来处理一下. 打开php.ini, 参数  设置  说明 fil ...

  3. 差分约束 【bzoj2330】[SCOI2011]糖果

    /*[bzoj2330][SCOI2011]糖果 2014年3月5日1,2761 Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖 ...

  4. Intellij IDEA常用配置记录

    换个IDE试试. 一个地址 http://intellij.mandroid.cn/ http://idea.imsxm.com/ http://idea.iteblog.com/key.php TO ...

  5. 如何在一个function里面设置一个全局的变量?

    答:解决方法是在function的开始插入一个global声明: def f() global x

  6. oracle中时间格式时候的大于号是大于和等于的意思

    oracle中时间格式时候的大于号是大于和等于的意思

  7. java1.8 lambda进行并行运算

    parallelStream()支持并行运算: package com.roocon.thread.t2; import java.util.Arrays; import java.util.List ...

  8. 【spark 算子案例】

    package spark_example01; import java.io.File; import java.io.FileWriter; import java.io.IOException; ...

  9. mybatis设置Map空值返回

    mybatis时,设置Map返回,当值为空时属性也会没有 在application.properties中加入下面配置,将会解决这个问题. #当查询数据为空时字段返回为null,不加这个查询数据为空时 ...

  10. viewbag

    How does ViewBag in ASP.NET MVC work behind the scenes? https://stackoverflow.com/a/16950197/3782855 ...