Balance POJ - 1837 地推
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 递推,注意到砝码一边的最大重量不超过7500,讲7500设为新的0点,枚举所有物品选择和节点选择,注意剪枝。。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = * ; #define INF 0x3f3f3f3f //0 1 背包
/*
dp[i][MAXN]
*/
int dp[][MAXN];
int x[], w[];
int solve(int c, int g)
{
for (int i = ; i <= g; i++)
{
for (int v = ; v < MAXN; v++)
{
if (dp[i - ][v])
{
for (int j = ; j <= c; j++)
{
dp[i][v + w[i] * x[j]] += dp[i - ][v];
}
}
}
}
return dp[g][];
}
int main()
{
int c, g;
scanf("%d%d", &c, &g);
memset(dp, , sizeof(dp));
for (int i = ; i <= c; i++)
scanf("%d", &x[i]);
for (int j = ; j <= g; j++)
scanf("%d", &w[j]);
/*for (int i = 0; i < c; i++)
{
for (int j = 0; j < g; j++)
{
dp[0][x[i] * w[j] + 7500]++;
}
}*/
dp[][] = ;
printf("%d\n", solve(c, g));
return ;
}
Balance POJ - 1837 地推的更多相关文章
- Balance POJ - 1837
Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...
- 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
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9240 Accepted: 5670 Description G ...
- 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个挂 ...
随机推荐
- P1372 又是毕业季I
题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在毕业晚会上,相信,这一定 ...
- css3中的变换、动画和过渡
变换:分为2d变换和3d变换,但一次只能用一个变换属性,多个的话最后一个会覆盖前面所有最终被浏览器实现,变换可以成为过渡和动画的一个待变参数(类似width,opacity等). 过渡:是动画的初始模 ...
- thinkphp5 404 file_put_contents 无法打开流:权限被拒绝
如果你用TP的时间比较长,或者说你比较了解TP的人都会知道,TP的runtime它需要的权限是很大的,如果你只给一般权限肯定是不行的,通常都是给runtime权限:777: linux命令如下: cd ...
- redis-3.0.1 sentinel 主从高可用 详细配置
最近项目上线部署,要求redis作高可用,由于redis cluster还不是特别成熟,就选择了redis sentinel做高可用.redis本身有replication,实现主从备份.结合sent ...
- 小写bool和大写BOOL的区别
转:https://blog.csdn.net/ji0525084/article/details/8594469 bool是标准C++中的布尔量,占一个字节大小内存,只有false或者true.具有 ...
- ubuntu12.04 配置apache+modwsgi+django1.5
1.首先下载modwsgi 链接如下: http://files.cnblogs.com/baoyiluo/mod_wsgi-3.4.zip 2.解压并安装mod_wsgi: ./configure ...
- 根据数据库表自动生成实体类、xml和dao---mybatis
网盘链接: https://pan.baidu.com/s/1AVGz0bDa_Y5zjk7vXa2eHw 提取码: 2gr6 1.记事本打开generatorConfig.xml文件 2(1,2,3 ...
- 显微镜下的webpack4入门
前端的构建打包工具很多,比如grunt,gulp.相信这两者大家应该是耳熟能详的,上手相对简单,而且所需手敲的代码都是比较简单的.然后webpack的出现,让这两者打包工具都有点失宠了.webpack ...
- 使用枚举(emum)代替常量类
原文: 作者:逍遥不羁 来源:CSDN 原文:https://blog.csdn.net/javaloveiphone/article/details/52371706 版权声明:本文为博主原创文章, ...
- nginx虚拟主机配置实践
1.配置基于域名的虚拟主机 [root@web01 html]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.defaul ...