描述:

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.

输入:

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 .

输出:

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.

样例输入:

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

样列输出:

2
4

题目大意:先输入一个正整数表示测试样例,每一个测试样例包含一个正整数n(表示种数)和一个实数p(表示概率),接下去n行包含两个正整数表示价值与概率。求概率小于等于p情况下所能得到的最大价值。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct asd
{  int value;  double p;
}gw[105];
int main()
{  int t,n,allvalue,k;  double a,dp[10005];  scanf("%d",&t);  while(t--){  scanf("%lf %d",&a,&n);  a=1-a;                                                  //安全的概率 allvalue=0;  for(int i=1;i<=n;i++){  scanf("%d %lf",&gw[i].value,&gw[i].p);  gw[i].p=1-gw[i].p;  allvalue+=gw[i].value;  }  memset(dp,0,sizeof(dp));  dp[0]=1;  for(int i=1;i<=n;i++){  for(int j=allvalue;j>=gw[i].value;j--){  dp[j]=max(dp[j],dp[j-gw[i].value]*gw[i].p);         //最大情况出现的两种可能性 }  }  for(int i=allvalue;i>=0;i--){  if(dp[i]>=a){  k=i;break;  }  }  printf("%d\n",k);}  return 0;
} 

Robberies(01背包的概率问题)相关推荐

  1. HDOJ2955 Robberies(01背包,概率)

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道DP题WA了. 今天看了一下,WA在了double max(int x,int y)上,x和y都应该是 ...

  2. HDU 1203 I NEED A OFFER! (动态规划、01背包、概率)

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU - Robberies(01背包)

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

  4. HDOJ 2955 Robberies (01背包)

    10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...

  5. 暑假N天乐 —— 01背包及变形

    暑假集训的第一天 第二天了. 决定还是先把基础巩固一下好了,万一后面训练赛出事故更尴尬. 所以今天的主题是 -- 01背包及变形 动态规划概念 动态规划(Dynamic programming,DP) ...

  6. HDU 2955 Robberies(概率DP,01背包)题解

    题意:给出规定的最高被抓概率m,银行数量n,然后给出每个银行被抓概率和钱,问你不超过m最多能拿多少钱 思路:一道好像能直接01背包的题,但是有些不同.按照以往的逻辑,dp[i]都是代表i代价能拿的最高 ...

  7. 01背包+概率dp Just another Robbery 抢银行

    题意:有n各个银行,每个银行有v[ i ]的钱并且有x [ i ] 的被抓住啊概率,如果被抓概率<=p,那么他是安全的,求他期望的最大钱数. 输入 3    //3组 0.04 3 1 0.02 ...

  8. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  9. HDU1203_I NEED A OFFER!【01背包】

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

最新文章

  1. Vue项目自动转换 px 为 rem,高保真还原设计图
  2. leetcode 104. Maximum Depth of Binary Tree
  3. 【PhotoScan精品教程】任务三:生成密集点云、生成网格、生成DEM、生成DOM
  4. 【学习笔记】网络层:应用模型、DNS系统、文件传输协议FTP
  5. 了解这些坑,再也不会出现诡异的BUG了~
  6. Java基础学习总结(102)——Java相关的开源项目
  7. 详解:Oracle数据库介绍 、字符、类型、语言
  8. php如何打包成apk,windows下PHP批量生成打包android程序APK
  9. 某游戏浏览器Flash加速dll调用,打造我们自己的Flash加速器
  10. Android简单闹钟设置
  11. linux usb模拟网卡,开发板作为USB设备模拟网卡(linux usb 网卡)--gadgetrndis|cdc
  12. 护腰暖腹的好伙伴,让腰部远离寒风侵袭
  13. 经典100句——人生与社会
  14. 一个不错的404页页【非常抱歉,全站内容审核中...】
  15. 查看服务器型号和cpu参数等信息
  16. 经典的网站反爬手段(超实用)
  17. 使用支付宝实现零手续费跨行转帐。
  18. [转]NodeJS初探
  19. 在线CAD-webpack使用插件入门
  20. 待办清单和日程计划表哪个会更好?可做日程表和待办提醒管理的便签

热门文章

  1. Windows下Tesseract4.0识别与中文手写字体训练
  2. 第一步商用计算机,清华同方T46H博仕商用笔记本u盘把win7系统改为win10系统的操作步骤...
  3. Centos中安装kenlm
  4. ajax技术优点和缺点,介绍Ajax技术
  5. Firefox F12 + Python 3.6 下载B站视频
  6. task1 赛题理解
  7. 决定系数 coefficient of determination的两种计算方法
  8. zzuli 1787: 生化危机 (BFS)
  9. Windows Presentation Foundation 巡游
  10. dnf加物理攻击的卡片有哪些_dnf哪些卡片是加物理攻击力的?