【hdu2955】 Robberies 01背包】的更多相关文章

Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 21060    Accepted Submission(s): 7808 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that…
Robberies  HDU2955 因为题目涉及求浮点数的计算:则不能从正面使用01背包求解... 为了能够使用01背包!从唯一的整数(抢到的钱下手)... 之后就是概率的问题: 题目只是给出被抓的几率,如果同时抢两家银行的话,那么被抓的概率是: (1-一家不被抓的概率*另一家不被抓的概率) 才是同时抢两家被抓的概率! 最后和题目给出的概率比较取较大值... 那么赋初值的时候dp[0]=1. 注意:不要误以为精度只有两位. #include<iostream> #include<std…
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在给定一个概率P,表示盗贼愿意冒险抢劫所能承受的最大被抓概率. 思路:首先用1减去被抓概率,得到安全概率.那抢劫了多家银行后的安全概率就是这些银行各自的安全概率连乘起来.其实是01背包的变种, dp[j] 表示获得金额 j 时的安全概率.这里用滚动数组,得方程  dp[j] = max(dp[j],…
/*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): 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): 31769    Accepted Submission(s): 11527 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 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的逃跑概率,1-逃跑概率就是最后被抓的概率,dp的话,以所有银行总金额为容量,以单个银行的金额为体积,以逃跑的概率为价值,跑01背包,最后找一下小于被抓概率的最大金额. 实现代码: #include<bits/stdc++.h> using namespace std; ; ],b[M]; int…
题意:有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])\] 第一维其实可以节省下来,因为之和前一…
这题有些巧妙,看了别人的题解才知道做的. 因为按常规思路的话,背包容量为浮点数,,不好存储,且不能直接相加,所以换一种思路,将背包容量与价值互换,即令各银行总值为背包容量,逃跑概率(1-P)为价值,即转化为01背包问题. 此时dp[v]表示抢劫到v块钱成功逃跑的概率,概率相乘. 最后从大到小枚举v,找出概率大于逃跑概率的最大v值,即为最大抢劫的金额. 代码: #include <iostream> #include <cstdio> #include <cstring>…
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…