Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18808    Accepted Submission(s): 6941

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 robbery only for a short while, before retiring to a comfortable
job at a university.


For
a few months now, Roy has been assessing the security of various banks
and the amount of cash they hold. He wants to make a calculated risk,
and grab as much money as possible.

His mother, Ola, has
decided upon a tolerable probability of getting caught. She feels that
he is safe enough if the banks he robs together give a probability less
than this.

 
Input
The
first line of input gives T, the number of cases. For each scenario,
the first line of input gives a floating point number P, the probability
Roy needs to be below, and an integer N, the number of banks he has
plans for. Then follow N lines, where line j gives an integer Mj and a
floating point number Pj .
Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj .
 
Output
For
each test case, output a line with the maximum number of millions he
can expect to get while the probability of getting caught is less than
the limit set.

Notes and Constraints
0 < T <= 100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0 <= Pj <= 1.0
A bank goes bankrupt if it is robbed, and you may assume that all
probabilities are independent as the police have very low funds.

 
Sample Input
3
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
 
Sample Output
2
4
6
 
题意:一群强盗想要抢劫银行,总共N(N <= 100)个银行,第i个银行的资金为Bi亿,抢劫该银行被抓概率Pi,问在被抓概率小于p的情况下能够抢劫的最大资金是多少?
题解:分析:至少一次被抓的概率要小于p,和hdu 1203 非常相似,抢劫第i个银行被抓的概率为pi,那么
不被抓的概率就为1-pi,定义dp[i] 代表获得能够获得i亿的情况下不被抓的最大概率,1-dp[i]代表被抓至少一次的最小概率
然后逆序枚举dp 得到第一个 1-dp[k] < p (k从V->0) 即为所求.
 
  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<string.h>
  4. #include<iostream>
  5. #include <math.h>
  6. #define N 10050 ///背包容量 100*100
  7. using namespace std;
  8.  
  9. int V[];
  10. double p[];
  11. double dp[N]; ///dp[i]表示抢劫i亿元能够不被抓的最大概率
  12. int main()
  13. {
  14. int tcase ;
  15. scanf("%d",&tcase);
  16. while(tcase--){
  17. int n;
  18. double _p;
  19. scanf("%lf%d",&_p,&n);
  20. int sum=;
  21. for(int i=;i<=n;i++){
  22. scanf("%d%lf",&V[i],&p[i]);
  23. sum +=V[i];
  24. p[i]=-p[i];
  25. }
  26. memset(dp,,sizeof(dp));
  27. dp[]=1.0; ///初始化,获得0亿元不被抓的概率为1
  28. for(int i=;i<=n;i++){
  29. for(int v = sum;v>=V[i];v--){
  30. dp[v] = max(dp[v],dp[v-V[i]]*p[i]);
  31. }
  32. }
  33. int max_value=;
  34. for(int k = sum;k>=;k--){
  35. if(-dp[k]<_p) {
  36. max_value = k;
  37. break;
  38. }
  39. }
  40. printf("%d\n",max_value);
  41. }
  42. return ;
  43. }

hdu 2955(概率转化,01背包)的更多相关文章

  1. HDU 2955 Robberies (01背包,思路要转换一下,推荐!)

    题意: 小A要去抢劫银行,但是抢银行是有风险的,因此给出一个float值P,当被抓的概率<=p,他妈妈才让他去冒险. 给出一个n,接下来n行,分别给出一个Mj和Pj,表示第j个银行所拥有的钱,以 ...

  2. HDU 2955 Robberies(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:一个抢劫犯要去抢劫银行,给出了几家银行的资金和被抓概率,要求在被抓概率不大于给出的被抓概率的情况下, ...

  3. HDU 2955 变形较大的01背包(有意思,新思路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others) ...

  4. HDU 2955 Robberies【01背包】

    解题思路:给出一个临界概率,在不超过这个概率的条件下,小偷最多能够偷到多少钱.因为对于每一个银行都只有偷与不偷两种选择,所以是01背包问题. 这里有一个小的转化,即为f[v]代表包内的钱数为v的时候, ...

  5. hdu 2955 Robberies(01背包)

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. HDU 5234 Happy birthday 01背包

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  7. hdu1203--D - I NEED A OFFER!(转化01背包)

    D - I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  8. Hdu 2955 Robberies 0/1背包

    Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. HDU 2602 Bone Collector(01背包裸题)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. sed 用法 转https://www.cnblogs.com/Dev0ps/p/8441255.html

    假设文档内容如下: [root@localhost ~]# cat /tmp/input.txt null test 要求:在1111之前添加AAA,方法如下: sed -i 's/指定的字符/要插入 ...

  2. Extjs 动态修改gridPanel列头信息以及store数据的方法

    1 /*******************************checkbox按钮 历史报警信息**************************************/ var check ...

  3. sql中按in中的ID进行排序输出

    builder.OrderBy("charindex(','+convert(varchar,ID)+',',',"+chufenOrder+"') ");

  4. 正确理解WPF中的TemplatedParent

    (注:Logical Tree中文称为逻辑树,Visual Tree中文称为可视化树或者视觉树,由于名称不是很统一,文中统一用英文名称代表两个概念,况且VisualTreeHelper和Logical ...

  5. JSX 的基本语法规则

    JSX 的基本语法规则:遇到 HTML 标签(以 < 开头),就用 HTML 规则解析:遇到代码块(以 { 开头),就用 JavaScript 规则解析

  6. Tomcat免安装版+Eclipse配置

    Tomcat是目前比较流行的开源且免费的Web应用服务器,在我的电脑上第一次安装Tomcat,再经过网上教程和自己的摸索后,将这个过程 重新记录下来,以便以后如果忘记了可以随时查看. 注意:首先要明确 ...

  7. intellij idea 破解补丁激活

    一.说明 idea激活可以用JetBrains account,Activation Code注册码或者填License server网址,使用注册码的方式可以参考lanyun提供的注册码,但是有效时 ...

  8. Jmeter-分布式

    转载自: http://www.51testing.com/html/28/116228-247521.html 由于Jmeter本身的瓶颈,当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发 ...

  9. 一个App架构例子分析--UI层使用MVP模式;各层之间使用Otto实现通信

    一.这个App整体的架构划分: 分为四大模块:   1.app模块 2.common模块 3.domain模块 4.model模块     app模块的依赖: dependencies {     c ...

  10. 【BZOJ1221】【HNOI2001】软件开发 [费用流]

    软件开发 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 某软件公司正在规划一项n天的软件开 ...