Sticks(poj1011/uva307)】的更多相关文章

题目大意: 乔治有一些碎木棒,是通过将一些相等长度的原始木棒折断得到的,给出碎木棒的总数和各自的长度,求最小的可能的原始木棒的长度:(就是将一些正整数分组,每组加起来和相等,使和尽可能小) 一开始做poj 32ms过,但uva3000 ms 都超时...而且poj discuss里给出了一组bT数据,最后uva 0.2sac的代码也跑了3 .4秒左右.discuss里的大牛据说什么奇偶性剪枝0.01ms过,可惜搜了半天也没找到具体方法.这题就这样过好了..(参考各种空间博客才艰难ac.不过此题实…
题目链接 http://poj.org/problem?id=1011 题意 输入n根棍子的长度,将这n根棍子组合成若干根长度相同的棍子,求组合后的棍子的最小长度.这题是poj2362的加强版,思路与poj2362相同,只是在2362的基础上添加了剪枝操作,做这题之前先去做poj2362效果最好. 思路 由于棍子越长,组合时的灵活性越差,所以要先从长棍子开始搜索,则首先要将n根棍子从长到短排序,然后从最长的棍子开始dfs.由于棍子最多可以有64根,不剪枝的话肯定会超时.以下是几种剪枝方法: (1…
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 h…
[题目描述] 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. P…
题目大意:用n根长度未必相等的木棒匹配出最多数量的等长木棒. 题目分析:枚举所有可能的等长木棒的长度,通过DFS的方式逐根匹配,在此过程中要剪枝.先将木棒长度按从大到小排序,也就是说匹配每一根等长木棒时总是优先挑选长的.剪枝方案如下:1. 若第i-1根木棒在当前方案的匹配中没有用到并且length[i]==length[i-1],则第i根木棒也不可能用到:2.若已匹配成功cnt根等长木棒,而第cnt+1根匹配不成功,则要剪枝:3.若在匹配第cnt+1根木棒时,最长的那根木棒stick会第一个被选…
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such…
题目:http://poj.org/problem?id=2653 题意:题意很简单,就是在地上按顺序撒一对木棒,看最后有多少是被压住的,输出没有被压住的木棒的序号.(有点坑的就是没说清楚木棒怎么算压住,也不知道是不是规范相交.) 分析: 我的代码是规范相交的情况,怎么说呢这题的数据有点水,我搜了别人的代码,他们都写的是包括不规范相交的情况.不规范相交已补,包括顶点相交 代码: #include <iostream> #include <string.h> #include <…
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…
题目大意: George有许多长度相同的木棍,随机的将这些木棍砍成小木条,每个小木条的长度都是整数单位(长度区间[1, 50]).现在George又想把这些小木棒拼接成原始的状态,但是他忘记了原来他有多少根木棍,也忘记了木棍的长度.现在请你编写一个程序,找到最短的原始的木棍长度. 输入: 每个测试案例包含两行,第一行表示小木条的总个数(最多64根小木条),第二行表示每个小木条的长度,用空格分开.当第一行输入为零的时候表示程序结束. 输出: 对于每个测试案例输出最短的木棍长度. 解题思路: 用搜索…
http://acm.uestc.edu.cn/#/problem/show/1218 既然二维dp表示不了,就加一维表示是否在边界放置,放置一个,两个.有一个trick就是如果只放一根,那么多长都可以. wa了好多次(囧) 开始因为l[i]/2会出现小数,没注意,把所有的长度都x2就可以解决. 又wa了n次因为没注意j-l[i]时没加判断,为什么不是RE呢!不开心... /********************************************* Memory: 1140 KB…