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

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…
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): 13854 Accepted Submission(s): 5111 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the…
题意:有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…
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…
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…
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 算法学习-–动态规划初探 题意分析 有一个小偷去抢劫银行,给出来银行的个数n,和一个概率p为能够逃跑的临界概率,接下来有n行分别是这个银行所有拥有的钱数mi和抢劫后被抓的概率pi,求在不被抓的情况下,小偷能抢到的最多的钱是多少. 显然这是一道概率问题,计算小偷不能逃的概率是不好算的,不如计算他成功的概率.若把题目中每个数据变成能够逃跑的概率,那就是1-pi. 我们先举个简单的例子. 不妨假设有3个银行: ①如果小偷都能抢劫,那么抢劫后能逃跑的概率就是(1-p1) * (1-p…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道题求不被抓时的最大金钱.金额是整数,概率是小数.因为数组小标不能是小数,所以我们可以以钱作为weight,概率作为value. 这说明解背包问题时cost和weight不是定死的,是可以相互转换的. 以银行的的总金额作为V,安全概率作为value,金额作为cost,安全概率=各家银行安全概率之积 #include <iostream> #include <string> #includ…
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 29495 Accepted Submission(s): 10795 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the…
题意: 小偷去抢银行,他母亲很担心. 他母亲希望他被抓的概率真不超过P.小偷打算去抢N个银行,每个银行有两个值Mi.Pi,Mi:抢第i个银行所获得的财产 Pi:抢第i个银行被抓的概率 求最多能抢得多少财产. 思路: 由于概率不是整数,所以不能将其作为背包容量.继续观察,发现Mi是整数,调整思路可发现,可以将财产作为背包容量,求一定财产内的被抓的最小概率.这样只需要判断这个概率是否小于等于P即可. 代码: double P; int N; int m[105]; double p[105]; do…
#include<stdio.h> #include<string.h> #define N 1100 int dp[N]; int main() { int n,t,m,a[N],b[N],i,j,v; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&v); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(…
题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高价值,但是这里的代价是小数,显然不能这么做.还有,被抓概率显然不能直接相加,也不能相乘(越乘越小),这里就需要一些转化.我们把被抓概率转化为逃跑概率也就是1-被抓,那么逃跑概率就能直接相乘了.dp[i]代表拿到i价值的最大逃跑概率,这样又变成了01背包.最后求逃跑概率大于等于1-m的最大的钱. 代码…
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…
题目链接: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…
分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意购买菜,即∑p - max_p +5 <= m  时,re = m - ∑p 2.当余额不充足时,有一种特殊情况,不能消费的情况,即m<5时    re = m; 3.余额不足时,只能购买部分菜,转化成01背包问题,找出最接近最接近5的值, 状态转换方程: f[0][P] = true;f[0][…
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),表示他对这件奖品的喜好值.现在他想知道,凭借他手上的这…
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…
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…
饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28562    Accepted Submission(s): 9876 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无…
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…
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j \right] = \max \left\{ {dp\left[ j \right],dp\left[ {j - a\left[ i \right].w} \right] + a\left[ i \right].v} \right\}\] 如果要求第K优解,那么状态 dp[j] 就应该是一个大小为…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5817    Accepted Submission(s): 3067 Problem Description The title of this…
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在给定一个概率P,表示盗贼愿意冒险抢劫所能承受的最大被抓概率. 思路:首先用1减去被抓概率,得到安全概率.那抢劫了多家银行后的安全概率就是这些银行各自的安全概率连乘起来.其实是01背包的变种, dp[j] 表示获得金额 j 时的安全概率.这里用滚动数组,得方程  dp[j] = max(dp[j],…
也是好题,带限制的01背包,先排序,再背包 这题因为涉及到q,所以不能直接就01背包了.因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],…,dp[m],再对第二个进行背包的时候,如果是普通的,应该会借用前面的dp[8],dp[7]之类的,但是现在这些值都是0,所以会导致结果出错.于是要想到只有后面要用的值前面都可以得到,那么才不会出错.设A:p1,q1 B:p2,q2,如果先A后B,则至少需要p1+q2的容量,如果先B后A,至少需要p2+q1的容量…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 34192 Accepted Submission(s): 14066 Proble…