Robberies

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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

 #include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int val[] ;
double cat[] ;
double pro ;
int n ;
double dp[] ; int main () {
// freopen ("a.txt" , "r" , stdin ) ;
int T ;
int sum ; scanf ("%d" , &T ) ;
while (T-- ) {
scanf ("%lf%d" , &pro , &n) ;
sum = ;
for (int i = ; i < n ; i++ ) {
scanf ("%d%lf" , &val[i] , &cat[i]) ;
sum += val[i] ;
}
// printf ("sum=%d\n" , sum ) ; memset (dp , , sizeof(dp) );
dp[] = ;
for (int i = ; i < n ; i++ ) {
for (int j = sum ; j >= val[i] ; j-- ) {
dp[j] = max (dp[j] , dp[j - val[i]] * (1.0 - cat[i]) ) ; } } for (int i = sum ; i >= ; i-- ) {
if ( dp[i] > - pro ) {
printf ("%d\n" , i ) ;
break ;
}
} }
return ;
}

用总金额代表dp范围

Robberies的更多相关文章

  1. Hdu 2955 Robberies 0/1背包

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

  2. HDU2955 Robberies[01背包]

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

  3. Robberies(HDU2955):01背包+概率转换问题(思维转换)

    Robberies  HDU2955 因为题目涉及求浮点数的计算:则不能从正面使用01背包求解... 为了能够使用01背包!从唯一的整数(抢到的钱下手)... 之后就是概率的问题: 题目只是给出被抓的 ...

  4. HDU 2955 Robberies 背包概率DP

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

  5. HDOJ 2955 Robberies (01背包)

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

  6. Robberies(简单的01背包 HDU2955)

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

  7. hdu 2955 Robberies 0-1背包/概率初始化

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

  8. hdu 2955 Robberies

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

  9. hdoj 2955 Robberies

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

随机推荐

  1. 云计算之路-阿里云上:Wireshark抓包分析一个耗时20秒的请求

    这篇博文分享的是我们针对一个耗时20秒的请求,用Wireshark进行抓包分析的过程. 请求的流程是这样的:客户端浏览器 -> SLB(负载均衡) -> ECS(云服务器) -> S ...

  2. 获取、增加、修改、删除sqlserver字段描述

    先看添加与删除字段描述 EXEC sys.sp_addextendedproperty @name = N'MS_Description', --添加Type字段说明 @value = N'屏蔽类型对 ...

  3. jquery hasClass、removeClass、addClass方法

    hasClass(class) 检查当前的元素是否含有某个特定的类,如果有,则返回true. 参数: class:用于匹配的类名. ---------------------------------- ...

  4. [bzoj 1064][NOI2008]假面舞会(dfs判断环)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1064 分析: 如果a看到b,则a->b 那么: 1.如果图中有环,则说明这个环的 ...

  5. 第三十九课:requestAnimationFrame详解

    大家应该都知道,如果一个页面运行的定时器很多,无论你怎么优化,最后肯定会超过指定时间才能完成动画.定时器越多,延时越严重. 为此,YUI,kissy等采用中央队列的方式,将定时器减少至一个.浏览器厂商 ...

  6. AngularJs-指令1

    前言: 前面写的有些乱,并且有些罗嗦,以后会注意的.希望我写的文章能帮助大家. 1,什么是指令 简单的说,指令是angularjs在html页面中建立一套自己能识别的标签元素.属性.类和注释,用来达到 ...

  7. MySQL配置

    一.登录MySQL 要登录到MySQL只需要使用如下命令. mysql -h localhost -u root -p localhost:IP地址: root:用户名: database:数据库名( ...

  8. 每天一个linux命令(17):locate 命令

    locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...

  9. Rhino Mock

    mock interfaces, delegates and classes, including those with parameterized constructors. set expecta ...

  10. iOS不得姐项目--appearance的妙用,再一次设置导航栏返回按钮,导航栏左右按钮的封装(巧用分类)

    一.UI_APPEARANCE_SELECTOR 彩票项目中appearance的用法一直没有搞明白,这次通过第二个项目中老师的讲解,更深一层次的了解到了很多关于appearance的作用以及使用方法 ...