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. 如果拼起来的长度大于你所要的木棍长度的话,需要继续判断,因为可能和之后的可以拼在一起,所以这里需要分情况考虑。

     

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

  • 相关阅读:
    jquery json 格式教程
    不修改代码就能优化ASP.NET网站性能的一些方法
    C#操作sqlite数据库使用SQLiteParameter传递参数
    60个开发者不容错过的免费资源库
    Java 与 .NET 的平台发展之争
    “一次编写,随处运行” Intel HTML5技术研讨会
    Struts2 高危漏洞修复方案 (S2-016/S2-017)
    AspNetPager 控件使用
    jQueryUI常用功能实战
    验证码生成类
  • 原文地址:https://www.cnblogs.com/OFSHK/p/11222065.html
Copyright © 2011-2022 走看看