当前位置:网站首页>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:如果当前木棒的长度已经出现过并且没有被使用 那么直接跳过
边栏推荐
- The fuse: OAuth 2.0 four authorized login methods must read
- TiDB 6.0 Placement Rules In SQL Usage Practice
- Integration testing of software testing
- What do T and Z in the time format 2020-01-13T16:00:00.000Z represent and how to deal with them
- Android 开发用 Kotlin 编程语言 二 条件控制
- 朴素贝叶斯
- PostgreSQL 2022 Report: Rising popularity, open source, reliability and scaling key
- 5G NR 系统消息
- Flink Yarn Per Job - RM启动SlotManager
- Scaling-law和模型结构的关系:不是所有的结构放大后都能保持最好性能
猜你喜欢
随机推荐
“蘑菇书”是怎样磨出来的?
How about Ping An Mengwa Card Insurance?Let parents read a few ways to identify products
PHP高级检索功能的实现以及动态拼接SQL
苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷
朴素贝叶斯
图像分割模型——segmentation_models_pytorch和albumentations 组合实现多类别分割
【加密解密】明文加密解密-已实现【已应用】
微信小程序标题栏封装
互联网行业凛冬之至,BATM的程序员是如何应对中年危机的?
How OpenHarmony Query Device Type
.NET in-depth analysis of the LINQ framework (6: LINQ execution expressions)
Student Information Management System (first time...)
STM32 entry development: write XPT2046 resistive touch screen driver (analog SPI)
安全软件Avast与赛门铁克诺顿NortonLifeLock合并获英国批准
5G NR system messages
MMDetection in action: MMDetection training and testing
TiDB 6.0 Placement Rules In SQL Usage Practice
一张图看懂 SQL 的各种 join 用法!
Android development with Kotlin programming language II Conditional control
Naive bayes








