zoukankan      html  css  js  c++  java
  • 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  就更新为最优那种方式,放在最顶层的书的厚度之和

  • 相关阅读:
    阿蒂亚谈数学——我对《数学的统一性》的笔记
    陶哲轩实分析习题8.5.6
    陶哲轩实分析习题8.5.2
    陶哲轩实分析习题8.5.9
    陶哲轩实分析习题8.5.5
    陶哲轩实分析习题8.5.6
    陶哲轩实分析习题8.5.2
    陶哲轩实分析习题8.5.1
    陶哲轩实分析习题8.5.9
    陶哲轩实分析习题8.5.5
  • 原文地址:https://www.cnblogs.com/EdwardLiu/p/4282920.html
Copyright © 2011-2022 走看看