POJ 1837 Balance 水题, DP 难度:0
题目
http://poj.org/problem?id=1837
题意
单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物与重物之间,钩子与钩子之间彼此不同。忽略杠杆及重心的影响,有多少种方式使得全部重物都挂上钩子(某些钩子可能挂若干个重物)后杠杆平衡?
思路
由于状态比较小,即使n的五次方也足以承受,而且任意时刻杠杆的状态在[-15 * 25 * 20, 15 * 25 * 20]之间,所以可以直接穷举状态。
感想
代码
#include <iostream>
#include <cstdio>
#include <assert.h>
#include <map>
#include <cstring> using namespace std; const int maxc = 15;
const int maxg = 25;
const int cnum = 20;
const int gnum = 20; const int base = maxc * maxg * cnum;
const int maxsta = base * 2 + 1; int h[maxc];
int w[maxg];
int a[maxg + 1][maxsta]; int main() {
int c, g;
cin>>c>>g;
for(int i = 0; i < c; i++) {
cin>>h[i];
}
for(int i = 0; i < g; i++) {
cin>>w[i];
}
a[0][base] = 1;
for(int i = 0;i < g;i++){
for(int j = 0; j < maxsta;j++){
if(a[i][j] == 0)continue;
for(int k = 0;k < c;k++){
//cout<<i + 1<<" " <<j + w[i] * h[k] - base<<a[i][j]<<endl;
a[i + 1][j + w[i] * h[k]] += a[i][j];
}
}
}
cout<<a[g][base]<<endl;
return 0;
}
POJ 1837 Balance 水题, DP 难度:0的更多相关文章
- POJ 1837 -- Balance(DP)
POJ 1837 -- Balance 转载:優YoU http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- poj 1837 Balance(背包)
题目链接:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- poj 3264 RMQ 水题
题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- POJ 3126 Prime Path 广度优先搜索 难度:0
http://poj.org/problem?id=3126 搜索的时候注意 1:首位不能有0 2:可以暂时有没有出现在目标数中的数字 #include <cstdio> #include ...
- Poj 1552 Doubles(水题)
一.Description As part of an arithmetic competency program, your students will be given randomly gene ...
- POJ 1837 Balance(01背包变形, 枚举DP)
Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 - ...
随机推荐
- Codeforces 1016 E - Rest In The Shades
E - Rest In The Shades 思路: 相似 红色的长度等于(y - s) / y 倍的 A' 和 B' 之间的 fence的长度 A' 是 p 和 A 连线和 x 轴交点, B'同理 ...
- IOException parsing XML document from class path resource [WebRoot/WEB-INF/applicationContext.xml];
parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io. ...
- 雷林鹏分享:使用 XSLT 显示 XML
使用 XSLT 显示 XML 通过使用 XSLT,您可以把 XML 文档转换成 HTML 格式. 使用 XSLT 显示 XML XSLT 是首选的 XML 样式表语言. XSLT(eXtensible ...
- 分享WCF文件传输---WCFFileTransfer
前几天分享了分享了WCF聊天程序--WCFChat , 本文和大家一起分享利用WCF实现文件的传输.程序运行效果:接收文件端:发送文件端:连接WCF服务,选择要传输的文件文件传输成功:我们会在保存文件 ...
- WAV和PCM文件转换的程序
using System;using System.IO;using System.Text;using System.Windows.Forms;using System.Runtime.Inter ...
- hdu-3001 三进制状态压缩+dp
用dp来求最短路,虽然效率低,但是状态的概念方便解决最短路问题中的很多限制,也便于压缩以保存更多信息. 本题要求访问全图,且每个节点不能访问两次以上.所以用一个三进制数保存全图的访问状态(3^10,空 ...
- 关于*[pylint]E1101:Module 'xxx' has no 'xxx' member* 简单而有效的解决办法
关于 pylint 的 *E1101* 错误: 概念: %s %r has no %r member Function %r has no %r member Variable %r has no % ...
- bzoj2342: [Shoi2011]双倍回文 pam
题解:先建pam,然后在fail树上dfs,从上到下的链如果有当前长度最远回文串的一半,那么更新答案 //#pragma GCC optimize(2) //#pragma GCC optimize( ...
- 【基础知识】【1】CDN
正文: CDN:Content Delivery Network,内容分发网络.使用户访问离ta最近的资源服务器,优化访问速度 优点: 1,内容可以共享,不同站点的同一文件可以不用多次缓存 2,增加下 ...
- WEB环境相关技术、配置
一.简介(基本概念) web开发中基本概念和用到的技术: A — AJAX AJAX 全称为“ Asynchronous JavaScript and XML ”(异步 JavaScript 和 XM ...