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

题意 小偷有个总的逃跑概率,每个银行有一个钱数和逃跑概率,问在总的逃跑概率下能最多获得多少钱?

思路:开始有0-1背包写,把概率扩大100倍,wa了,重改思路。把总价格当容量,被抓的概率为价值 在被抓的概率大于总概率时的容量为多少

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <stack>
  6. #include <queue>
  7. #include <math.h>
  8. #include <vector>
  9. using namespace std;
  10. #define N 10100
  11. #define ll long long
  12. #define INF 0x3f3f3f3f
  13. #define PI 3.1415926535897932
  14. #define met(a,b) memset(a,b,sizeof(a));
  15. vector<vector<int> >Q;
  16. double w[N],dp[N];
  17. int v[N];
  18. int main()
  19. {
  20. int t,sum,n;
  21. double p;
  22. scanf("%d",&t);
  23. while(t--)
  24. {
  25. sum=;
  26. scanf("%lf %d",&p,&n);
  27. p=-p;
  28. for(int i=;i<=n;i++)
  29. {
  30. scanf("%d %lf",&v[i],&w[i]);
  31. w[i]=-w[i];
  32. sum+=v[i];
  33. }
  34. met(dp,);
  35. dp[]=;
  36. for(int i=;i<=n;i++)
  37. {
  38. for(int j=sum;j>=v[i];j--)
  39. dp[j]=max(dp[j],dp[j-v[i]]*w[i]);
  40. }
  41. for(int i=sum;i>=;i--)
  42. {
  43. if(dp[i]>=p)
  44. {
  45. printf("%d\n",i);
  46. break;
  47. }
  48. }
  49. }
  50. return;
  51. }

1 . Robberies (hdu 2955)的更多相关文章

  1. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

  2. Robberies(HDU 2955 DP01背包)

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

  3. Robberies hdu 2955 01背包

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

  4. Robberies HDU - 2955

    直接说题意吧.(什么网友bb了半天题都说不清楚) 给了  P  表示大于这个概率一定被抓住.则P表示被抓住的概率.N表示现在有的银行,pi表示被抓的概率嘛. 然后,就看数学了.肯定不能算被抓的概率啊. ...

  5. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  6. [HDU 2955]Robberies (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意是给你一个概率P,和N个银行 现在要去偷钱,在每个银行可以偷到m块钱,但是有p的概率被抓 问 ...

  7. HDU 2955 Robberies(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目: Problem Description The aspiring Roy the Rob ...

  8. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

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

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

随机推荐

  1. IOS实用功能之截图(来自相册和拍照)

    // //  ViewController.m //  MyImagePicker1.0 // //  Created by Mac on 14-7-14. //  Copyright (c) 201 ...

  2. DB2 重新设定表自增字段的当前值

    转自:http://blog.csdn.net/jionghan3855/article/details/2709073 1.ALTER TABLE UKEY_INFO_TAB ALTER COLUM ...

  3. 开始研究Ray tracing

    几个月前面试时Boss问过我一个问题--"除了scanline渲染方法,你还知道什么其他渲染方式?",我没答出来,至今记忆犹新. 前段时间摆弄Intel VTune时看了它的示例代 ...

  4. ASP.NET Core环境配置

    一.环境准备 vs2015 update3 下载NET Core Tooling Preview 2 for Visual Studio 2015 (下载地址:https://go.microsoft ...

  5. JavaScript中数组操作

    var arr1=new Array(); arr1.push(1);//在数组的中末尾添加元素,并返回新的长度 arr1.push(2);//在数组的中末尾添加元素,并返回新的长度 arr1.pop ...

  6. java解析excel2003和excel2007:The supplied data appears to be in the office 2007+XML Polonly supports OLE2 office documents

    上传excel解析存到数据库时报: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears ...

  7. Blending(融合)

        Src Pixesl: 源像素 : 指的是当前光栅化产生的值     Dst Pixels 目标像素.指的是先前渲染存储在RT中的值     可以用来实现那些效果,诸如水,玻璃 以及其他的,( ...

  8. 最近在用placeholder ,是已有的,网上也有不少都是jq写的

    其实除了支持placeholder 的浏览器,其他用js 或jq实现的都不叫placeholder 效果,只能算上是获取焦点,或失去焦点时的一个placeholder 没有出生时就已经存在效果 很多人 ...

  9. 用英文加优先级来解读C的声明

    比如:int ( * func_p ) ( double ); 首先着眼于标识符. func_p is 因为存在括号,(* func_p) 先被处理,这里着眼于* func_p is a pointe ...

  10. [转]15 个顶级 HTML5 游戏引擎

    本文转自:http://www.open-open.com/news/view/13874db 1) HTML5 Game Engine Construct 2 is a leading high q ...