您当前的位置: 主页网站优化软件知识

[回溯剪枝] pku1011 解题报告

发布于:2014-03-17 18:38:11  作者:兄弟网络   点击:

Sticks
Time Limit:1000MS  Memory Limit:10000K
Total Submit:24457 Accepted:5494

Description
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 contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.

Output
The output should 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

对于准备学习回溯剪枝的人来说,这道题是再适合不过了 :)
s[]记录数据,将数据按递减顺序排序,搜索数d,len = sum/d
目标:搜索len的组合

解题思路:
 1. res+s[i] == d
 搜索成功返回1,否则返回0
 2. res+s[i] < d
 选取s[i]结点, 继续从下一点开始搜索,成功则返回1;
 如果失败,判断本次搜索起始是否是一个搜索起始段,即res=0,如果是,手机APP ,则
返回0。因为此时s[i]必为从最左端开始搜索,第一个还没有被用的点,故而如果
有解,则必然包含s[i],所以,本次搜索如果失败,在res=0的情况下,网站SEO,返回0
减少不必要的搜索。




 

本文关键词: 回溯| 剪枝| pku1011| 解题| 报告|

[相关阅读]

我们介绍

  兄弟网络科技工作室,专业从事日照百度推广,日照百度优化,日照网站建设,日照网络公司,日照网站制作,日照网站优化,日照软件制作。如果您感觉我们不错请分享↓给更多的人

收缩