Robberies

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

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
用逃脱概率比作价值,所抢钱数比作背包容量。
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. float dp[+];
  6. struct node
  7. {
  8. int a;
  9. float b;
  10. }f[];
  11. int main()
  12. {
  13. int T,i,j,n;
  14. float p;
  15. freopen("in.txt","r",stdin);
  16. scanf("%d",&T);
  17. while(T--)
  18. {
  19. int sum=;
  20. memset(dp,,sizeof(dp));
  21. scanf("%f%d",&p,&n);
  22. for(i=;i<=n;i++)
  23. {
  24. scanf("%d%f",&f[i].a,&f[i].b);
  25. f[i].b=-f[i].b;
  26. sum+=f[i].a;
  27. }
  28. dp[]=1.0;
  29. for(i=;i<=n;i++)
  30. {
  31. for(j=sum;j>=f[i].a;j--)
  32. {
  33. if(dp[j]<dp[j-f[i].a]*f[i].b)
  34. dp[j]=dp[j-f[i].a]*f[i].b;
  35. }
  36. }
  37. for(i=sum;i>=;i--)
  38. if(dp[i]>=(1.0-p))
  39. break;
  40. printf("%d\n",i);
  41. }
  42. return ;
  43. }

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

  1. Robberies hdu 2955 01背包

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

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

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

  3. hdu 2955 01背包

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

  4. HDU 2955 01背包(思维)

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

  5. 1 . Robberies (hdu 2955)

    The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...

  6. Robberies HDU - 2955

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

  7. HDU 2955 Robberies 背包概率DP

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

  8. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  9. hdu 5445 多重背包

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

随机推荐

  1. 百度地图api实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx ...

  2. Qt5+VS2013兼容XP方法

    用Qt5+VS2013编译程序默认配置会在XP运行时报"不是有效的Win32程序"工作需要必须要XP运行 pro文件中加一句: 复制代码 QMAKE_LFLAGS_WINDOWS ...

  3. 微信授权登陆接入第三方App(步骤总结)Android

    微信授权登陆接入第三方App(步骤总结)Android Android App实现第三方微信登录

  4. Struts2源代码解读之Action调用

    对于Struts2源代码的分析已经有些时日了,虽然网上有很多解读代码,不过自己还是写一个放上来,供大家参考一下. 解读过程: 直接在action类中打断点(包括构造函数和待执行方法)进行debug调试 ...

  5. 40个UI设计工具

    摘要:用户界面设计在持续的基础上不断成长和演变.要跟上时代,你需要关注趋势.新资源和正被实施和谈论的新技术. 导读:用户界面设计在持续的基础上不断成长和演变.要跟上时代,你需要关注趋势.新资源和正被实 ...

  6. Java日志终极指南

    Java日志基础 Java使用了一种自定义的.可扩展的方法来输出日志.虽然Java通过java.util.logging包提供了一套基本的日志处理API,但你可以很轻松的使用一种或者多种其它日志解决方 ...

  7. Linux SD/MMC/SDIO驱动分析

    一.SD/MMC/SDIO概念区分 SD(SecureDigital)与 MMC(MultimediaCard) SD 是一种 flash memory card 的标准,也就是一般常见的 SD 记忆 ...

  8. Thinkphp交友手机首页简明前台、后台

    先来说下后台吧,后台要写后台模板-V,后台控制器-C 后台模板如下代码: <!DOCTYPE html> <html> <head> <meta charse ...

  9. DoTween学习笔记(二) UGUI结合使用(实现一些简单效果)

    UGUI官方实例中是使用Animation来控制UI的移动,放大缩小动画等等, Animation来控制UI的动画工作量实在是太多了, 所以我们一般使用itween,DoTween. 来控制动画, 这 ...

  10. python urllib基础学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #使用python创建一个简单的WEB客户端 import urll ...