当前位置:网站首页>hdu1455 Sticks(搜索+剪枝+剪枝+.....+剪枝)
hdu1455 Sticks(搜索+剪枝+剪枝+.....+剪枝)
2022-08-05 11:30:00 【51CTO】
Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10325 Accepted Submission(s): 3091
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
Source
Recommend
lcy | We have carefully selected several similar problems for you: 1258 1067 1045 2553 1426
Statistic |
Submit |
Discuss |
Note
我觉得我要死了 参考了别人的代码 理解了一晚上
自己敲了下。在hdu过了 可是在 nyoj293死活TLE。。
明明和别人同样的代码。最后顺序 变量名 什么都改 还是不行。。我选择死亡 nyoj的我不刷了
对于这道题而言 剪枝在搜索中的重要性体现的淋漓尽致。
剪枝1:小木棒的长度 越长约束力也就越大,灵活度就越小(能够组合的长度越少),所以首先对小木棒的长度排序
剪枝2:所有小木棒的长度之和肯定能够整除原来小木棒的长度
剪枝3:如果我们已经使用过木棒4 5 6无法完成拼接,下次再出现5 4 6肯定是不可能的 所以搜索时要避免这种情况
剪枝4:如果当前搜索的结果是正确的,对于每根小木棒 都要使用,如果发现没有使用 直接退出
剪枝5:如果当前木棒的长度等于拼接木棒需要的长度 ,并且这根木棒没有被使用,那么直接退出。(即使找到比他小的几个组合为这个木棒长度 也是无用)
剪枝6:如果当前木棒的长度已经出现过并且没有被使用 那么直接跳过
边栏推荐
猜你喜欢
随机推荐
Android 开发用 Kotlin 编程语言一 基本数据类型
图像分割模型——segmentation_models_pytorch和albumentations 组合实现多类别分割
有多一只“手”的机器狗出没?就在昇腾AI开发者创享日·南京站
Linux:记一次CentOS7安装MySQL8(博客合集)
前沿技术数字孪生如何应用在智慧城市上?
UDP通信
自定义过滤器和拦截器实现ThreadLocal线程封闭
#yyds干货盘点#JS数组和树相互转化
安全软件Avast与赛门铁克诺顿NortonLifeLock合并获英国批准
hdu2097 nyoj414 sky数 (进制转换)
I'm going crazy.Again A few days can not be A problem
四、kubeadm单master
字节秋招二面把我干懵了,问我SYN报文什么情况下会被丢弃?
动手学深度学习_GoogLeNet / Inceptionv1v2v3v4
UDP communication
Flink Yarn Per Job - RM启动SlotManager
祝所有码农七夕快乐~
el-menu箭头改为右下
力扣330 按要求补齐数组(贪心)
PostgreSQL 2022 报告:流行度上涨,开源、可靠性和扩展是关键









