zoukankan      html  css  js  c++  java
  • UVA307Sticksdfs+剪枝

    George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero. Input The input file contains blocks of 2 lines. The first line contains the number of sticks parts after cutting. The second line contains the lengths of those parts separated by the space. The last line of the file contains ‘0’. Output The output file contains the smallest possible length of original sticks, one per line.

    Sample Input

    9

    5 2 1 5 2 1 5 2 1

    4

    1 2 3 4

    0

    Sample Output

    6

    5

    题意:给出一个n代表n根小木棍的长度,将这n根小木棒随意组合拼凑起来的木棍的长度一样且最小。

    思路:需要多处剪枝

    1. 木棍的长度一定会是这些所有木块总和的因数,而且木棍长度一定大于所有分割好的木棍中最长的木棍。
    2. 将木棍从大到小排序,因为这样可以快一点搜索出这个木棍的长度是否能够被拼出。
    3. 如果发现当前这个长度的木棍块没有办法和后面的木棍拼出来的话,那么如果i-1和当前的木棍长度相等的话就可以不判断这个木棍了。
    4. 如果拼起来的长度大于你所要的木棍长度的话,需要继续判断,因为可能和之后的可以拼在一起,所以这里需要分情况考虑。

     

    但是我代码还没写出来。。。

  • 相关阅读:
    C#中int和System.Int32理解总结
    谈C#中的Delegate
    Html的安全隐患
    Oracle性能优化
    Selenium私房菜系列7 深入了解Selenium RC工作原理(2)
    java取整和java四舍五入方法
    Android SufaceView 背景设置透明
    android图片加水印,文字
    关于android集成开发环境引入jar包错误的问题
    android bitmap绘制文字自动换行
  • 原文地址:https://www.cnblogs.com/OFSHK/p/11222065.html
Copyright © 2011-2022 走看看