当前位置:网站首页>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:如果当前木棒的长度已经出现过并且没有被使用 那么直接跳过
边栏推荐
- Machine Learning - Logistic Regression
- PostgreSQL 2022 Report: Rising popularity, open source, reliability and scaling key
- 一张图理解EOS是什么
- 时间格式2020-01-13T16:00:00.000Z中的T和Z分别表示什么,如何处理
- 5G NR system messages
- How to write a blog with Golang - Milu.blog development summary
- 【MySQL基础】-【数据处理之增删改】
- power failure...Trouble trouble trouble!!!
- 2022技能大赛训练题:交换机snmp配置
- Flink Yarn Per Job - JobManger 申请 Slot
猜你喜欢
随机推荐
GPU-CUDA-图形渲染分析
Discover the joy of C language
API 网关简述
【加密解密】明文加密解密-已实现【已应用】
数据治理体系演进简介
Mathcad 15.0软件安装包下载及安装教程
时间格式2020-01-13T16:00:00.000Z中的T和Z分别表示什么,如何处理
OpenHarmony如何查询设备类型
记2022年七夕感慨
智能算力的枢纽如何构建?中国云都的淮海智算中心打了个样
【深度学习】mmclassification mmcls 实战多标签分类任务教程,分类任务
互联网行业凛冬之至,BATM的程序员是如何应对中年危机的?
Four, kubeadm single master
Google启动通用图像嵌入挑战赛
2022杭电多校联赛第六场 题解
Android development with Kotlin programming language II Conditional control
大佬们 我是新手,我根据文档用flinksql 写个简单的用户访问量的count 但是执行一次就结束
巴比特 | 元宇宙每日必读:中国1775万件数字藏品分析报告显示,85%的已发行数藏开通了转赠功能...
nyoj757 期末考试 (优先队列)
MMDetection in action: MMDetection training and testing