hdoj--2955--Robberies(背包好题)】的更多相关文章

Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi,求在不被抓的情况下,小偷能抢到的最多的钱是多少. 显然这是一道概率问题,计算小偷不能逃的概率是不好算的,不如计算他成功的概率.若把题目中每个数据变成能够逃跑的概率,那就是1-pi. 我们先举个简单的例子. 不妨假设有3个银行: ①如果小偷都能抢劫,那么抢劫后能逃跑的概率就是(1-p1) * (1-p…
10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9836    Accepted Submis…
A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2955 Appoint description: Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usu…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15522    Accepted Submission(s): 5708 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12161    Accepted Submission(s): 4527 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 31769    Accepted Submission(s): 11527 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高价值,但是这里的代价是小数,显然不能这么做.还有,被抓概率显然不能直接相加,也不能相乘(越乘越小),这里就需要一些转化.我们把被抓概率转化为逃跑概率也就是1-被抓,那么逃跑概率就能直接相乘了.dp[i]代表拿到i价值的最大逃跑概率,这样又变成了01背包.最后求逃跑概率大于等于1-m的最大的钱. 代码…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大价值. 分组背包模版题. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib&g…
背包九讲下载CSDN 背包九讲内容 多重背包: hdu 2191 珍惜现在,感恩生活 多重背包入门题 使用将多重背包转化为完全背包与01背包求解: 对于w*num>= V这时就是完全背包,完全背包为何只与01背包在循环上不同,因为01背包,每个物品只能取一次,所以要逆序:而完全背包,每个物品的数量无限多个,这就需要建在在之前已经取到了当前要取的基础之上: 同时01背包使用二进制优化处理:即使用二进制表示最优的可取值: 二进制优化的技巧:1,2,4,...,2k−1,n[i]−2k +1(循环之外…
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,仅仅有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前. 死亡骑士:"我要买道具!" 地精商人:"我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个." 死亡骑士:"好的,给我一个血…
Description     约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草.  顿因有H(1≤H≤5000)包干草,每一包都有它的体积Vi(l≤Vi≤C).约翰只能整包购买, 他最多可以运回多少体积的干草呢? Input     第1行输入C和H,之后H行一行输入一个Vi. Output       最多的可买干草体积. Sample Input 7 3  //总体积为7,用3个物品来背包 2 6 5 Th…
#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了! 小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要need(i)张奖券进行兑换,同时也只能兑换一次,为了使得辛苦得到的奖券不白白浪费,小Ho给每件奖品都评了分,其中第i件奖品的评分值为value(i),表示他对这件奖品的喜好值.现在他想知道,凭借他手上的这…
寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17092    Accepted Submission(s): 8800 Problem Description 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前.死亡骑士:…
Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible fro…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469    Accepted Submission(s): 25209 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo…
题目链接 很明显的一道完全背包板子题,做法也很简单,就是要注意 这里你可以买比所需多的干草,只要达到数量就行了 状态转移方程:dp[j]=min(dp[j],dp[j-m[i]]+c[i]) 代码如下: #include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …  The bone collect…
HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N (N<32768) 兑换成硬币有非常多种兑法. 请你编程序计算出共同拥有多少种兑法. 分析:基础的全然背包问题. 本题限制条件是: 金钱总数<=N. 本题目标条件是: 求构造方法数目. 令dp[i][j]==x 表示用前i种硬币构造j 美分共同拥有x种方法. 初始化:  dp为全0且dp[0][0]…
完全背包模板题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define inf 0x3f3f3f3f ],v[],f[]; int main() { int T,v1,v2,n; scanf("%d",&T); while(T--){ scanf("%d%d",&v1,&v2); scanf(&q…
多重背包模板题 #include<iostream> #include<cstring> #include<algorithm> using namespace std; ],w[]; ],num[]; int main() { int T,vn,n; scanf("%d",&T); while(T--){ memset(f,,sizeof(f)); scanf("%d%d",&vn,&n);//总金额 总…
Divideing Jewels 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Mary and Rose own a collection of jewells. They want to split the collection among themselves so that both receive an equal share of the jewels. This would be easy if all the jewels had the sa…
hdu1864 01背包 题目链接 题目大意:一堆数,找到一个最大的和满足这个和不超过Q要学会分析复杂度! #include <cstdio> #include <cstring> #define MAX(a,b) (a>b?a:b) ; int dp[N],data[N]; float bound; int n,cnt; int main(){ char type; ],tprice; while(scanf("%f%d",&bound,&…
Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side are the same weight. Weights can be put on left side or right side arbitrarily. Please tell whether the balance can measure an object of weight M. In…
1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi为整数).求背包能够容纳的最大价值.   输入 第1行,2个整数,N和W中间用空格隔开.N为物品的种类,W为背包的容量.(1 <= N <= 100,1 <= W <= 50000) 第2 - N +…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22658    Accepted Submission(s): 8358 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16522    Accepted Submission(s): 6065 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10526    Accepted Submission(s): 3868 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(1-P)为价值,即转化为01背包问题. 此时dp[v]表示抢劫到v块钱成功逃跑的概率,概率相乘. 最后从大到小枚举v,找出概率大于逃跑概率的最大v值,即为最大抢劫的金额. 代码: #include <iostream> #include <cstdio> #include <cstring>…
题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以及抢劫该银行被抓的可能性. 注意:抢劫各个银行被抓的可能是独立事件! 思路: 由于被抓的可能性float型,而且不仅仅只有两位,float型精度一般小数点后6-7位, 假若将被捕可能性看做容量,开10^6的数组,WA:开10^7的数组,MLE. 因此若从一般的角度,即将被捕可能性转化成整数,看做容量,将抢…
/*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13854 Accepted Submission(s): 5111 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the…