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: 书架问题的更多相关文章

  1. ASP.NET Core MVC 打造一个简单的图书馆管理系统 (修正版)(一) 基本模型以及数据库的建立

    前言: 本系列文章主要为我之前所学知识的一次微小的实践,以我学校图书馆管理系统为雏形所作. 本系列文章主要参考资料: 微软文档:https://docs.microsoft.com/zh-cn/asp ...

  2. Summary of Critical and Exploitable iOS Vulnerabilities in 2016

    Summary of Critical and Exploitable iOS Vulnerabilities in 2016 Author:Min (Spark) Zheng, Cererdlong ...

  3. 三个不常用的HTML元素:<details>、<summary>、<dialog>

    前面的话 HTML5不仅新增了语义型区块级元素及表单类元素,也新增了一些其他的功能性元素,这些元素由于浏览器支持等各种原因,并没有被广泛使用 文档描述 <details>主要用于描述文档或 ...

  4. [LeetCode] Summary Ranges 总结区间

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  5. Network Basic Commands Summary

    Network Basic Commands Summary set or modify hostname a)     temporary ways hostname NEW_HOSTNAME, b ...

  6. Summary - SNMP Tutorial

    30.13 Summary Network management protocols allow a manager to monitor and control routers and hosts. ...

  7. Mac Brew Install Nginx Summary

    ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.1.el_capitan.bot################# ...

  8. [BZOJ1861][Zjoi2006]Book 书架

    [BZOJ1861][Zjoi2006]Book 书架 试题描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候 ...

  9. Android分享一款漂亮的折叠书架菜单

    一个Android折叠书架菜单,效果极佳,给人的视觉感觉很好,便于使用. FoldingMenu

随机推荐

  1. Firefox --- 火狐浏览器下载

    http://www.firefox.com.cn/download/

  2. ldap 配置过程详解

    ldap常用名称解释 1.环境搭建 操作系统:centos6.5 x86_64关闭防火墙.selinux开启时间同步# crontab -e加入# time sync*/5 * * * * /usr/ ...

  3. jquery validator

    jQuery.validate是一款非常不错的表单验证工具,简单易上手,而且能达到很好的体验效果,虽然说在项目中早已用过,但看到这篇文章写得还是不错的,转载下与大家共同分享. 一.用前必备 官方网站: ...

  4. Memcached存Session数据、访问安全性、使用场景总结(3)

    最近做了一个单点登录SSO,登陆后的凭证放到Memcached令牌放到Cookies:但是用户经常掉线,开发环境和测试却没有这个问题,最后从Memcached找到原因. Memcached概念.作用. ...

  5. 思科SVI接口和路由接口区别

    Cisco多层交换中提到了一个SVI接口,路由接口.在多层交换机上可以将端口配置成不同类型的接口. 其中SVI接口 类似于  interface Vlan10ip address 192.168.20 ...

  6. python-django开发学习笔记二

    1.简述 1.1 开发环境 该笔记所基于的开发环境为:windows8.python2.7.5.psycopg2-2.4.2.django1.5.4.pyCharm-2.7.3.以上所描述的软件.插件 ...

  7. JVM JRE JDK三者的区别和联系

    一. 详细介绍1.JVM -- java virtual machineJVM就是我们常说的java虚拟机,它是整个java实现跨平台的 最核心的部分,所有的java程序会首先被编译为.class的类 ...

  8. ASP.NET Web配置指南

    利用ASP.NET,可以指定影响服务器上所有的Web应用程序.仅影响单个的应用程序.影响个别页面.或影响Web应用程序中的个别文件夹的配置设置.可以对编译器选项.调试.用户身份验证.错误消息显示.连接 ...

  9. HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  10. HIT 2715 - Matrix3 - [最小费用最大流][数组模拟邻接表MCMF模板]

    题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2715 Time limit : 5 sec Memory limit : 64 M Zhouguyue ...