POJ 1837 Balance】的更多相关文章

 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…
题目: 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(…
题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物与重物之间,钩子与钩子之间彼此不同.忽略杠杆及重心的影响,有多少种方式使得全部重物都挂上钩子(某些钩子可能挂若干个重物)后杠杆平衡? 思路 由于状态比较小,即使n的五次方也足以承受,而且任意时刻杠杆的状态在[-15 * 25 * 20, 15 * 25 * 20]之间,所以可以直接穷举状态. 感想…
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9240 Accepted: 5670 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 n…
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…
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 negligible weight and each arm's length is 15. Some hooks are attached to these arms and…
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…
题意:给出一个天平,给出c个钩子,及c个钩子的位置pos[i],给出g个砝码,g个砝码的质量w[i],问当挂上所有的砝码的时候,使得天平平衡的方案数, 用dp[i][j]表示挂了前i个砝码时,平衡点为j时的总的方案数, 状态转移为第i个砝码是否挂上,如果要挂上第i个砝码的话,j>=pos[i]*w[i](力矩=力臂*力) 因为最大的力矩为 20*15*25=150000 #include<iostream> #include<cstdio> #include<cstri…
题目大意:给你一个天平,并给出m个刻度,n个砝码,刻度的绝对值代表距离平衡点的位置,并给出每个砝码的重量.达到平衡状态的方法有几种. 题目思路:首先我们先要明确dp数组的作用,dp[i][j]中,i为放置的砝码数量,j为平衡状态,0为平衡,j<0左倾,j>0右倾,由于j作为下标不能是负数,所以我们要找一个新的平衡点,因为15*20*20 = 7500,所以平衡点设置为7500, 然后我们可以得出动态方程 dp[i][j+w[i]*c[k])+=dp[i-1][j]; #include<c…
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 negligible weight and each arm's length is 15. Some hooks are attached to these arms and…
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 negligible weight and each arm's length is 15. Some hooks are attached to these arms and Gigel wants…
Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11878   Accepted: 7417 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 arm…
题意:一个天平上有C个挂钩,第i个挂钩的位置为C[i],C[i] < 0表示该挂钩在原点的左边,C[i] > 0表示该挂钩在原点的右边:然后给出G个钩码的重量,问有多少种挂法使得天平保持平衡. /* 首先定义一个平衡度j的概念:当平衡度j=0时,说明天枰达到平衡, j>0,说明天枰倾向右边(x轴右半轴),j<0则相反 f[i][j]表示钩码挂到第i个时,平衡度为j的方案数 由于距离c[i]的范围是-15~15,钩码重量的范围是1~25,钩码数量 最大是20,因此最极端的平衡度是所有…
题目链接:http://poj.org/problem?id=1837 题目大意: 有一个天平,左臂右臂各长15,然后给出n,m,n代表有几个挂钩,挂钩给出负数代表在左臂的距离,正数则在右臂m代表有m个砝码,要你求出使得这个天平保持平衡有几种方法,要求所有砝码全部使用完思路:首先我们先要明确dp数组的作用,dp[i][j]中,i为放置的砝码数量,j为平衡状态,0为平衡,j<0左倾,j>0右倾,由于j作为下标不能是负数,所以我们要找一个新的平衡点,因为15*20*20 = 7500,所以平衡点设…
Balance Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different fr…
一开始看到这个题 第一反应:暴搜! 看看数据范围 ...放弃了 然后就在各种憋状态转移方程. 各种不会 还是看了Discuss里面说的才有点儿思路 直接放状态转移方程: f[i][ j+ w[i]*c[k] ]= ∑(f[i-1][j]) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int m,n,l[66666],f[666][66666],q,w[666…
#include <cstdio> #include <memory.h> #include<iostream> using namespace std; ][]; //状态数组dp[i][j] int main(int i,int j,int k) { int n; //挂钩数 int g; //钩码数 ]; //挂钩位置 ]; //钩码重量 cin>>n>>g; ;i<=n;i++) cin>>c[i]; ;i<=g;…
题意:给你n个挂钩,m个砝码,要求砝码都用上,问有多少中方案数 题解:对于这道题目的状态,我们定义一个变量j为平衡度,当j=0的时候,表明天平平衡.定义dp[i][j]表达的含义为使用前n个砝码的时候,平衡度为j的方案数.计数类型的背包,更新的时候把每个砝码的所有可能贡献(每个砝码可以放在不同的钩子上,每个钩子的离中点的距离不一致)都updata一下就ok了.关键是状态的抓取,然后这个计数背包的理解. ac代码: #include <cstdio> #include <iostream&…
第一周: 经过漫长的时间,终于有时间来写一下结题报告. 地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=36180#overview A:POJ 1837       Balance      按偏移量DP                                                   题解 B:POJ 1948        Triangular Pastures   按边长DP                …
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈), 1742, 1887,1926(马尔科夫矩阵,求平衡), 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029,…
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740(博弈), 1742, 1887, 1926(马尔科夫矩阵,求平 衡), 1936,1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029,2…
Balance  POJ - 1837 题目大意: 有一个天平,天平左右两边各有若干个钩子,总共有C个钩子,有G个钩码,求将钩码全部挂到钩子上使天平平衡的方法的总数. 其中可以把天枰看做一个以x轴0点作为平衡点的横轴 输入: 2 4 //C 钩子数 与 G钩码数 -2 3 //负数:左边的钩子距离天平中央的距离:正数:右边的钩子距离天平中央的距离c[k] 3 4 5 8 //G个重物的质量w[i] /* 首先定义一个平衡度j的概念:当平衡度j=0时,说明天枰达到平衡, j>0,说明天枰倾向右边(…
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20…
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20…
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递推. 构造法.(POJ 3295) 模拟法.(POJ 1068,POJ 2632,POJ 1573,POJ 2993,POJ 2996) 二…
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递…
声明: 1.这份列表不是我原创的,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 195…
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 1003 Hangover792.762000 1001 Exponentiation752.486000 1006 Biorhythms705.902000 1005 I Think I Need a Houseboat686.540000 1011 Sticks647.566000 1007…
The Balance http://poj.org/problem?id=2142 Time Limit: 5000MS   Memory Limit: 65536K       Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 3…