POJ 1837 Balance 01背包】的更多相关文章

题目: http://poj.org/problem?id=1837 感觉dp的题目都很难做,这道题如果不看题解不知道憋到毕业能不能做出来,转化成了01背包问题,很神奇.. #include <stdio.h> #include <string.h> ][]; ], w[]; int main() { int n, m; scanf("%d %d", &n, &m); //天平上有n个砝码位置 ; i <= n; i++) { scanf(…
Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 -2 3 3 4 5 8 C = -2, G = 3, 那么 2*(3+4+5)=3*(8); 2*(4+8)=3*(3+5) 共有两种可行的方案, 那么结果就是2 Description Gigel has a strange "balance" and he wants to poise…
 POJ 1837 -- Balance 转载:優YoU   http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第一个冲动就是穷举....不过再细想肯定行不通= =O(20^20)等着超时吧... 我也是看了前辈的意见才联想到01背包,用动态规划来解 题目大意: 有一个天平,天平左右两边各有若干个钩子,总共有C个钩子,有G个钩码,求将钩码全部挂到钩子上使天平平衡的方法的总数. 其中可以把天枰看做一个以x轴0点作…
题目链接:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10983   Accepted: 6824 Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other…
Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9163   Accepted: 5617 Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negli…
题意:给定 n 个数,保证下一个数比上一个数和前一个数之和大,然后给定一个背包,问你最多放多少容积. 析:应该是很明显的01背包,但是可惜的是,数组开不出来,那就得考虑暴力,因为数不多,才几十而已,要不然就超int了,然后我就暴力做了,超时了, 这个还是前剪枝的,这样剪的,先把前几项和算出来,确定最大砝码的重量,然后在暴力时,如果发现剩下的比总和还小,或者等于,就不用再算了,直接结束就好了, 这样做时间竟然是0毫秒,可能是标程吧,并不是很理解为什么是0. 代码如下: #include <cstd…
题意: 小明有一个贤妻良母型的女朋友,他们两个一起洗衣服. 有M种颜色的N件衣服,要求洗完一种颜色的衣服才能洗另外一种颜色. 两人可以同时洗,一件衣服只能被一个人洗. 给出洗每件衣服所用的时间,求两个人洗完这些衣服所用的最短时间. 分析: 因为每种颜色是分开洗的,所以我们可以单独考虑一种颜色的衣服. 因为洗完这些衣服的总时间是固定的,所以两个人洗的时间尽可能的相等,这样洗完的时间最短. 所以将总时间的一半作为背包容量(这里总时间的奇偶性并不影响),物品的体积和价值都是洗每件衣服所用的时间,然后进…
Q: 如何判断几件物品能否被 2 辆车一次拉走? A: DP 问题. 先 dp 求解第一辆车能够装下的最大的重量, 然后计算剩下的重量之和是否小于第二辆车的 capacity, 若小于, 这 OK. Description Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping…
题目链接 Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping them relocate. To move the furniture, they only have two compact cars, which complicates everything a bit.…
Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10326   Accepted: 6393 题意:给你n个挂钩g个砝码  以及n个挂钩的距离天平中心距离(负的代表左边正的代表右边)g个砝码的重量. 要求输出能够令天平平衡的方法种类 解题思路     http://user.qzone.qq.com/289065406/blog/1299341345  非常具体 #include<iostream> #i…