HDU Problem - 1455 Sticks
題目鏈接
Problem 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 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
AC
- 剪枝的運用
- 首先從最長的木棒枚舉,滿足木棒總和是枚舉木棒的倍數
- 然后dfs看能否把所有木棒用完,如果用完就找到了一個最小的合適值
- 開始剪枝
- 如果進行一系列的搜索之后,發現當前這個木棒未完成匹配,而且當前所要匹配的是整個目標,這就不用接著往下dfs
舉個例子:木棒分別是 6 5 5 3 2 2, 你要找6, 第一個可以,接著匹配下一個6,找到5時發現沒有匹配的這時候直接退出就行,說明6不能構成完整的
總結
以上是生活随笔為你收集整理的HDU Problem - 1455 Sticks的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Problem - 4828 Grids
- 下一篇: HDU Problem - 5113 B