Summary: 书架问题
Consider the problem of storing n books on shelves in a library. The order of the books is fixed
by the cataloging system and so cannot be rearraged. Therefore, we can speak of a book bi, where
1 i n, that has a thickness ti and height hi. The length of each bookshelf at this library is L.
Now consider the case where the height of the
books is not constant, but we have the freedom to adjust the height of each shelf to that of the
tallest book on the shelf. Thus the cost of a particular layout is the sum of the heights of the largest
book on each shelf. (1) Give an example to show that the greedy algorithm of stuffing each shelf
as full as possible does not always give the minimum overall height.
书架问题:
Greedy 并非最有方法:
(1) Consider 3 books with the same thickness t, t = L/2. Book 1 has height h, while Book 2 and
3 has height 2h.
The greedy algorithm will put Book 1 and 2 in the first shelf and put Book 3 in the second shelf,
which makes the cost 2h + 2h = 4h.
However, the best strategy will put Book 1 in the first shelf and put Book 2 and 3 in the second
shelf, which makes the cost h + 2h = 3h.
Thus the greedy algorithm does not always give the minimum overall height.
一维DP:
维护量:S[i], The minimum height when putting i books on shelves.
l, 当前书架已利用宽度
思路就是:1. 利用l判断当前第i本书能不能放到当前层次,如果能放进去,就放,这样高度肯定最小,因为前面i-1本书的高度是最优,放进第i本并没有增加高度。这里有点类似Greedy。l也需要更新,因为放得下,就更新为 l+= 新的厚度;
2. 如果当前第i本书无法放进去,需要新开一层。这时候就要考虑,是不是需要把下面一层的书放到新的一层来,以优化高度。这里就体现DP了,greedy在这里就不一定最优了
这时候 l 就更新为最优那种方式,放在最顶层的书的厚度之和
Summary: 书架问题的更多相关文章
- ASP.NET Core MVC 打造一个简单的图书馆管理系统 (修正版)(一) 基本模型以及数据库的建立
前言: 本系列文章主要为我之前所学知识的一次微小的实践,以我学校图书馆管理系统为雏形所作. 本系列文章主要参考资料: 微软文档:https://docs.microsoft.com/zh-cn/asp ...
- Summary of Critical and Exploitable iOS Vulnerabilities in 2016
Summary of Critical and Exploitable iOS Vulnerabilities in 2016 Author:Min (Spark) Zheng, Cererdlong ...
- 三个不常用的HTML元素:<details>、<summary>、<dialog>
前面的话 HTML5不仅新增了语义型区块级元素及表单类元素,也新增了一些其他的功能性元素,这些元素由于浏览器支持等各种原因,并没有被广泛使用 文档描述 <details>主要用于描述文档或 ...
- [LeetCode] Summary Ranges 总结区间
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- Network Basic Commands Summary
Network Basic Commands Summary set or modify hostname a) temporary ways hostname NEW_HOSTNAME, b ...
- Summary - SNMP Tutorial
30.13 Summary Network management protocols allow a manager to monitor and control routers and hosts. ...
- Mac Brew Install Nginx Summary
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.1.el_capitan.bot################# ...
- [BZOJ1861][Zjoi2006]Book 书架
[BZOJ1861][Zjoi2006]Book 书架 试题描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候 ...
- Android分享一款漂亮的折叠书架菜单
一个Android折叠书架菜单,效果极佳,给人的视觉感觉很好,便于使用. FoldingMenu
随机推荐
- CF 166E Tetrahedron
E. Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 禁用ngen版本的.NET Framework dll加载
在调试时会发现出于性能考虑.NET Framework dll加载的都是ngen版本,比如:System.dll,实际加载System.ni.dll. 如果希望加载非ngen版本,可以设置系统环境变量 ...
- ps软件使用的问题解决记录
1.PS的字体颜色改变不了的解决方法,添加字体的时颜色无论怎么选都只能有[黑.白.灰]三种颜色, 问题的原因:图像的模式选择了灰度(G) 解决方法:图像-->模式-->RG ...
- 【CF653G】Move by Prime 组合数
[CF653G]Move by Prime 题意:给你一个长度为n的数列$a_i$,你可以进行任意次操作:将其中一个数乘上或者除以一个质数.使得最终所有数相同,并使得操作数尽可能小.现在我们想要知道$ ...
- 通过Adb 查看当前正在运行的Activity.
extends:http://www.cnblogs.com/tt_mc/p/4269833.html adb shell dumpsys activity activities | sed -En ...
- C# 验证XML
一.验证XML文档 若要验证 XML 文档,需要构造一个 XmlReaderSettings 对象,其中包含用于验证 XML 文档的 XML 架构定义语言 (XSD) 架构.Schema是用于描述和规 ...
- Unity3D笔记 愤怒的小鸟<六> 弹弓发射小鸟
要实现的目标 实现个性化的鼠标 实现弹弓 选择小鸟.拉升弹弓.发射小鸟 弹弓橡皮筋 声音 1.实现个性化鼠标 效果 2.添加弹弓 建立两个材质 创建一个空GameObject 把两个shoot拖进来统 ...
- 理解Buffer
Buffer对象是Node.js用来处理二进制数据的一个接口.JavaScript比较擅长处理Unicode数据,对于处理二进制格式的数据(比如TCP数据流),就不太擅长.Buffer对象就是为了解决 ...
- Redis的启动过程
本文主要介绍Redis启动加载过程,总体上可以分为如下几步: 1. 初始化全局服务器配置 2. 加载配置文件(如果指定了配置文件,否则使用默认配置) 3. 初始化服务器 4. 加载数据库 5. 网络监 ...
- POJ-2181 Jumping Cows(贪心)
Jumping Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7329 Accepted: 4404 Descript ...