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…
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…
01背包.将最大金额作为容量v.概率做乘法. #include <stdio.h> #include <string.h> #define mymax(a, b) (a>b) ? a:b ]; ]; ]; int main() { int case_n; float ff, f; int m, v; int i, j; scanf("%d", &case_n); while (case_n--) { scanf("%f %d",…
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): 10526    Accepted Submission(s): 3868 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问你被抓的概率在P以下,最多能偷多少钱. 刚开始我还在想,A银行被抓的概率是a,B银行被抓的概率是b,那么偷A和B被抓的概率是a*b.. 傻逼了- -..a*b是既被A银行抓又被B银行抓.. 所以用逃跑的概率计算 dp[i][j]代表从前i个银行里偷了j元逃跑的最大概率 代码: #include <c…
/*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…
Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7351    Accepted Submission(s): 2762 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 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank ro…
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decide…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的逃跑概率,1-逃跑概率就是最后被抓的概率,dp的话,以所有银行总金额为容量,以单个银行的金额为体积,以逃跑的概率为价值,跑01背包,最后找一下小于被抓概率的最大金额. 实现代码: #include<bits/stdc++.h> using namespace std; ; ],b[M]; int…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下,计算出所能抢劫得到的最多资金. 思路:一开始把被抓概率当做背包容量来做,结果错了,很重要的一点就是逃脱概率的计算,不是简单的相加相减,而是在上一家银行抢劫时的逃脱概率再乘以这一次的逃脱概率. 举个例子: 三家银行的被抓概率为P1,P2,P3.那么去抢劫这三家银行的逃脱概率为(1-P1)*(1-P2)…
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): 23142    Accepted Submission(s): 8531 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…
解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候,小偷不被逮捕的概率,这样我们在用 for(i=1;i<=n;i++) { for(v=vol;v>=0;v--) f[v]=max(f[v],f[v-c[i]]*(1-p[i]));} 的过程中,在求出最大的不被抓的概率过程中,记录下了在此过程中的包中的钱数与此时对应的概率,这样最后只需用一个循环…
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…
打算专题训练下DP,做一道帖一道吧~~现在的代码风格完全变了~~大概是懒了.所以.将就着看吧~哈哈 Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in t…
这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(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. 因此若从一般的角度,即将被捕可能性转化成整数,看做容量,将抢…
题意:有N个银行,每抢一个银行,可以获得\(v_i\)的前,但是会有\(p_i\)的概率被抓.现在要把被抓概率控制在\(P\)之下,求最多能抢到多少钱. 分析:0-1背包的变形,把重量变成了概率,因为计算概率需要乘积而非加法,所以不能直接用dp[j]表示概率为j时的最大收益. 令\(dp[i][j]\)表示对前\(i\)个银行,抢到价值为\(j\)还能保持安全的概率,则有递推式: \[dp[i][j] = dp[i-1][j-v[i]]*(1-p[i])\] 第一维其实可以节省下来,因为之和前一…
题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高价值,但是这里的代价是小数,显然不能这么做.还有,被抓概率显然不能直接相加,也不能相乘(越乘越小),这里就需要一些转化.我们把被抓概率转化为逃跑概率也就是1-被抓,那么逃跑概率就能直接相乘了.dp[i]代表拿到i价值的最大逃跑概率,这样又变成了01背包.最后求逃跑概率大于等于1-m的最大的钱. 代码…
题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个整数N,是准备抢的N个银行.接下来有N行代表N个银行,每行是一个整数M和一个浮点数P.M表示此银行钱的数量,P劫此银行会被抓的概率. 输出:低于规定的被抓概率,能抢多少钱? 思路: 注意到,这里的背包容量是概率!也就是浮点型,不适合作为容量.要找其他的背包容量才行. 将被抓的概率转为安全的概率,安全…
这道背包题和我们常见的背包题有所不同.如果根据以前做背包的惯性思维和题中数据的迷惑,会把概率乘以100来当作容量.但是经测试是不行的. 我们不妨换种思路,看做DAG上的DP思想.将所有有可能达到的钱的最大"逃跑"概率算出来,最后再将能够达到的最大的钱输出.而能不能够达到这个可以将所有除0以外的值初始化为0.意为逃跑的概率为0. #include<cstdio>#include<cstring>#include<algorithm>using name…
题意: 小偷去抢银行,他母亲很担心. 他母亲希望他被抓的概率真不超过P.小偷打算去抢N个银行,每个银行有两个值Mi.Pi,Mi:抢第i个银行所获得的财产 Pi:抢第i个银行被抓的概率 求最多能抢得多少财产. 思路: 由于概率不是整数,所以不能将其作为背包容量.继续观察,发现Mi是整数,调整思路可发现,可以将财产作为背包容量,求一定财产内的被抓的最小概率.这样只需要判断这个概率是否小于等于P即可. 代码: double P; int N; int m[105]; double p[105]; do…
1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : 1171 ( Big Event in HDU ) Judge Status : Accepted #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> us…
题目链接: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): 29618    Accepted Submission(s): 10834 Problem Description The aspiring Roy the Robb…
DP 158:11:22 1205:00:00   Overview Problem Status Rank (56) Discuss Current Time: 2015-11-26 19:11:23 Contest Type: Private Start Time: 2015-11-20 05:00:00 Contest Status: Running End Time: 2016-01-09 10:00:00 Manager: qwerqqq Clone this contest Edit…