HDU 2955 Robberies(01背包)】的更多相关文章

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的逃跑概率,1-逃跑概率就是最后被抓的概率,dp的话,以所有银行总金额为容量,以单个银行的金额为体积,以逃跑的概率为价值,跑01背包,最后找一下小于被抓概率的最大金额. 实现代码: #include<bits/stdc++.h> using namespace std; ; ],b[M]; int…
/*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…
题意:有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…
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): 29499 Accepted Submission(s): 10797 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the…
Robberies 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi,求在不被抓的情况下,小偷能抢到的最多的钱是多少. 显然这是一道概率问题,计算小偷不能逃的概率是不好算的,不如计算他成功的概率.若把题目中每个数据变成能够逃跑的概率,那就是1-pi. 我们先举个简单的例子. 不妨假设有3个银行: ①如果小偷都能抢劫,那么抢劫后能逃跑的概率就是(1-p1) * (1-p…