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 Submission(s): 3673

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<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int v[10001];
 6     double f[10001],w[10001];
 7     int i,j,n,m;
 8     int T;
 9     scanf("%d",&T);
10     while(T--)
11     {
12         double rate;
13         int sum=0;
14         scanf("%lf %d",&rate,&n);//rate被抓的概率,1-rate逃脱的概率
15         for(i=0;i<n;i++)
16         {
17             scanf("%d %lf",&v[i],&w[i]);
18             sum+=v[i];
19         }
20         memset(f,0,sizeof(f));
21         f[0]=1;//没偷逃脱的概率为1
22         for(i=0;i<n;i++)
23         {
24             for(j=sum;j>=v[i];j--)
25             {
26                 f[j]=f[j]>f[j-v[i]]*(1-w[i])?f[j]:f[j-v[i]]*(1-w[i]);//选择最大逃脱概率
27             }
28         }
29         for(i=sum;i>=0;i--)
30         {
31             if(f[i]>=1-rate)
32             {
33             printf("%d\n",i);
34             break;
35            }
36         }
37     }
38     return 0;
39 }

View Code

HDOJ 2955 Robberies (01背包)相关推荐

  1. HDOJ 2955 Robberies

    类似01背包的DP Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. HDU - Robberies(01背包)

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

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

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

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

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

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

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

  6. hdu 2955 01背包

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

  7. hdoj 1864 最大报销额 【01背包】||【dfs】

    最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  8. 01背包经典例题详解

    转载自点击打开链接 首先01背包题目的雏形是 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总和最大. 从这个题目中可以看出,01背包的特点 ...

  9. 【背包专题】01背包

    暑假集训开始了,按照队里的分配,我是弄DP的,嘛,于是我又一次的开始了从01背包开始学习,昨天将杭电的几道01背包重新做了一遍,下面讲讲我自己对于01背包的理解. 首先01背包题目的雏形是 有N件物品 ...

最新文章

  1. shell编程-条件判断
  2. Mac下如何显示隐藏文件/文件夹
  3. sql server set赋值和select 赋值的区别以及使用方法
  4. 电脑wifi不见了_大家好,我是来给你家 WiFi 提速的
  5. Linux编译安装 php soap模块
  6. subpage新写法
  7. iOS sqlite
  8. 李洋疯狂C语言之n个人报数,报到3的退出,最后留在场上的是原来的第几位(约瑟夫环)
  9. Python的小整数对象池
  10. BZOJ1354: [Baltic2005]Bus Trip
  11. Linux驱动开发-编写FT5X06触摸屏驱动
  12. 国内四大炒股软件APP 全面技术解析
  13. 搜狐新浪ip库查询接口的使用
  14. 2020最新PHP面试题(附带答案)
  15. ES冷热分离架构设计:一招让你的ELK日志系统节省 50% 的硬盘成本
  16. HBuilder封装APP
  17. OS_PV操作_4.过独木桥问题
  18. Perl-字符串与排序2
  19. Linux-包教包会系列之-shell
  20. Python编程实现计算存款利息

热门文章

  1. 《SolidWorks 2017中文版机械设计从入门到精通)》——1.6 参考基准轴
  2. PropertyGrid中的枚举显示为中文(转)
  3. 向域管理转型所遇到的问题
  4. html body不定宽居中,纯CSS实现元素垂直水平居中-非固定宽度
  5. mysql修改字段null为空字符串
  6. bootstrap inputfile.js
  7. thinkphp关联查询(多表查询)
  8. Golang并发读取超大文件
  9. Context是怎么在Go语言中发挥关键作用的
  10. 两片74161实现60进制_74ls161集成60进制加法计数 - 74LS161集成计数器电路(2、3、4、6、8、10、60进制计数器)...