POJ 1837 Balance
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 9240 | Accepted: 5670 |
Description
It orders two arms of negligible weight and each arm's length is 15. Some hooks are attached to these arms and Gigel wants to hang up some weights from his collection of G weights (1 <= G <= 20) knowing that these weights have distinct values in the range 1..25. Gigel may droop any weight of any hook but he is forced to use all the weights.
Finally, Gigel managed to balance the device using the experience he gained at the National Olympiad in Informatics. Now he would like to know in how many ways the device can be balanced.
Knowing the repartition of the hooks and the set of the weights write a program that calculates the number of possibilities to balance the device.
It is guaranteed that will exist at least one solution for each test case at the evaluation.
Input
the first line contains the number C (2 <= C <= 20) and the number G (2 <= G <= 20);
the next line contains C integer numbers (these numbers are also distinct and sorted in ascending order) in the range -15..15 representing the repartition of the hooks; each number represents the position relative to the center of the balance on the X axis (when no weights are attached the device is balanced and lined up to the X axis; the absolute value of the distances represents the distance between the hook and the balance center and the sign of the numbers determines the arm of the balance to which the hook is attached: '-' for the left arm and '+' for the right arm);
on the next line there are G natural, distinct and sorted in ascending order numbers in the range 1..25 representing the weights' values.
Output
Sample Input
2 4
-2 3
3 4 5 8
Sample Output
2
Source
DP......
#include <iostream>
#include <cstdio> #include <cstring> using namespace std; int tianping[30],fama[30],dp[30][11000],C,G; int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
POJ 1837 Balance的更多相关文章
- POJ 1837 -- Balance(DP)
POJ 1837 -- Balance 转载:優YoU http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第 ...
- poj 1837 Balance(背包)
题目链接:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- POJ 1837 Balance 01背包
题目: http://poj.org/problem?id=1837 感觉dp的题目都很难做,这道题如果不看题解不知道憋到毕业能不能做出来,转化成了01背包问题,很神奇.. #include < ...
- POJ 1837 Balance 水题, DP 难度:0
题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...
- POJ 1837 Balance(01背包变形, 枚举DP)
Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 - ...
- [poj 1837] Balance dp
Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...
- poj 1837 Balance (0 1 背包)
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10326 Accepted: 6393 题意:给你n个挂 ...
- POJ 1837 Balance 【DP】
题意:给出一个天平,给出c个钩子,及c个钩子的位置pos[i],给出g个砝码,g个砝码的质量w[i],问当挂上所有的砝码的时候,使得天平平衡的方案数, 用dp[i][j]表示挂了前i个砝码时,平衡点为 ...
- poj 1837 Balance 动态规划 (经典好题,很锻炼思维)
题目大意:给你一个天平,并给出m个刻度,n个砝码,刻度的绝对值代表距离平衡点的位置,并给出每个砝码的重量.达到平衡状态的方法有几种. 题目思路:首先我们先要明确dp数组的作用,dp[i][j]中,i为 ...
随机推荐
- HoloLens开发手记 - Unity之摄像头篇
当你穿戴好HoloLens后,你就会处在全息应用世界的中心.当你的项目开启了"Virtual Reality Support"选项并选中了"Windows Hologra ...
- 我从腾讯那“偷了”3000万QQ用户数据,出了份很有趣的独家报告!
声明: 1.目前程序已停止运行!QQ空间也已升级访问安全机制. 2.本“分析”数据源自部分用户的公开信息,并未触及隐私内容,广大网友无需担心. 3.QQ空间会不定期发布大数据分析报告,感兴趣的朋友关注 ...
- IOS动态判断UITextField是否输入为手机号
现在使用的app大部分都用到手机号注册,很多app注册的时候会判断手机号,可以根据当前输入文本来判断“获取验证码”的按钮是否可用 判断输入文本是通过UITextField的代理的 -(BOOL)tex ...
- 服务器网站报错:由于扩展配置问题无法提供您请求的页面,请添加MIME映射,针对mp4,flv文件类型无法打开。
确保IIS正常 服务器增加mp4格式的MIME 类型映射设置的具体步骤是: “开始” > “控制面板” > “管理工具” >“Internet 信息服务(IIS管理器)”,“MIME ...
- linux oracle磁盘满了
最近,查看我们一台linux服务器,发现硬盘空间都已经使用了95%,很是疑惑啊,怎么回事那?难道是数据库文件太大了? Filesystem Size Used Avail Us ...
- history命令显示出详细时间
文章摘自: http://blog.csdn.net/lixiaohuiok111/article/details/34428161 http://blog.csdn.net/lixiaohuiok1 ...
- Rhino Mock
mock interfaces, delegates and classes, including those with parameterized constructors. set expecta ...
- BZOJ-1705 Longge的问题 一维GCD SUM 乱搞+质因数分解+...
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 1871 Solved: 1172 [Submit][ ...
- Search everything 使用说明
Everything是速度最快的文件搜索软件,可以瞬间搜索到你需要的文件.
- 洛谷P2925 [USACO08DEC]干草出售Hay For Sale
题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...