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  就更新为最优那种方式,放在最顶层的书的厚度之和

时间: 2024-12-20 01:35:48

Summary: 书架问题的相关文章

【HTML5】summary交互元素

1.源码 <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"/> <title>交互元素summary的使用</title> <style type="text/css"> body{ padding:5px; font-size:14px; } summary{ font-weight:bold; } </style>

HDU 4989 Summary(数学题暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 Problem Description Small W is playing a summary game. Firstly, He takes N numbers. Secondly he takes out every pair of them and add this two numbers, thus he can get N*(N - 1)/2 new numbers. Thirdl

228. Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 这个题目不难,首先对原序列进行排序,然后要注意对特殊情况的处理.同时,要掌握string类的几个重要成员函数: to_string():将数字转换为

1926: [Sdoi2010]粟粟的书架

1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec  Memory Limit: 552 MBSubmit: 807  Solved: 321[Submit][Status][Discuss] Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Co rmen 的文章.粟粟家中有一个 R行C 列的巨型书架,书架的每一个位置都摆有一本书,上数第i 行.左数第j 列 摆放的书有Pi,j

Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary

Learning to Compare Image Patches via Convolutional Neural Networks ---  Reading Summary 2017.03.08 Target: this paper attempt to learn a geneal similarity function for comparing image patches from image data directly. There are several ways in which

BZOJ 1861: [Zjoi2006]Book 书架 (splay)

1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1453  Solved: 822[Submit][Status][Discuss] Description 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引力了,所以她看完后常常会忘记原来是放在书柜的什么位

[题解]bzoj 1861 Book 书架 - Splay

1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1396  Solved: 803[Submit][Status][Discuss] Description 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引力了,所以她看完后常常会忘记原来是放在书柜的什么位

【BZOJ-1926】粟粟的书架 二分 + 前缀和 + 主席树

1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec  Memory Limit: 552 MBSubmit: 616  Solved: 238[Submit][Status][Discuss] Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Cormen 的文章.粟粟家中有一个 R行C 列的巨型书架,书架的每一个位置都摆有一本书,上数第i 行.左数第j 列摆放的书有Pi,j页厚

三个不常用的HTML元素:&lt;details&gt;、&lt;summary&gt;、&lt;dialog&gt;

前面的话 HTML5不仅新增了语义型区块级元素及表单类元素,也新增了一些其他的功能性元素,这些元素由于浏览器支持等各种原因,并没有被广泛使用 文档描述 <details>主要用于描述文档或文档某个部分的细节,与<summary>配合使用可以为<details>定义标题.标题是可见的,用户点击标题时,显示出details [注意]这两个标签只有chrome和opera支持 <details> 该标签仅有一个open属性,用来定义details是否可见(默认为不