思路:

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. 068_不登陆虚拟机,修改虚拟机网卡 IP 地址

    #!/bin/bash #该脚本使用 guestmount 工具,Centos7.2 中安装 libguestfs-tools-c 可以获得 guestmount 工具#脚本在不登陆虚拟机的情况下,修 ...

  2. Python获取百度浏览记录

    Python模拟百度登录实例详解 http://www.jb51.net/article/78406.htm Python实战计划学习作业2-1 http://blog.csdn.net/python ...

  3. webservice企业开发实例

    1. 2. 3.环境变量的配置 4.创建动态web工程-->版本2.5-->tomcat7.0 第一步:创建cxf项目 第二步:添加cxf的jar包 全部将jar包拷入lib目录下 第三步 ...

  4. vue 的 watch 如何在初始化时执行

    之前的做法一直是在 created 钩子之后手动调用一次 created() { this.fetchText(); }, watch: { text: 'fetchText', } 后来在翻阅文档的 ...

  5. 【LGR-059】洛谷7月月赛题解

    传送门 比赛的时候正在大巴上,笔记本没网又没电(不过就算有我估计也不会打就是了) \(A\) 咕咕 const int N=(1<<10)+5; int a[N][N],n; void s ...

  6. Redis Mysql 双写一致性问题

    一:序 - 最近在对数据做缓存时候,会涉及到如何保证 数据库/Redis 一致性问题. - 刚好今天来总结下 一致性问题 产生的问题,和可能存在的解决方案. 二:(更新策略)-  先更新数据库,后更新 ...

  7. python对象调用父类的方法

    #类定义 class People: #定义基本属性 name = '' age = 0 #定义私有属性,私有属性在类外部无法直接进行访问 __weight = 0 #定义构造方法 def __ini ...

  8. Mininet系列实验(六):Mininet动态改变转发规则实验

    一. 实验目的 熟悉Mininet自定义拓扑脚本的编写:熟悉编写POX脚本动态改变转发规则 二.实验原理 在SDN环境中,控制器可以通过对交换机下发流表操作来控制交换机的转发行为.在本实验中,基于Mi ...

  9. OpenJudge计算概论-找和为K的两个元素

    /*============================================================== 找和为K的两个元素 总时间限制: 1000ms 内存限制: 65536 ...

  10. 如果你处理的是字节,那么 Go 语言可能是一个不错的选择。 如果你处理的是数据,那么 Go 语言可能不是一个好的选择。

    用Go语言编程的利与弊 AI前线小组 译 InfoQ 今天