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. 我是如何自学Android,资料分享(2015 版)

    自己学了两三个月的Android,最近花了一周左右的时间写了个App——Diigoer(已开源),又花了一两周时间找工作,收到了两个Offer,也算是对自己学习的一种认可吧:我刚开始学习总结的——&l ...

  2. 《android基于andFix的热修复方案》实战篇

    有篇文章说的比较简洁,大家可以参考下:AndFix使用说明 下面说说实际使用中遇到的问题 1:如何继承到gradle项目中 dependencies { compile 'com.alipay.eul ...

  3. 第二章 Js函数

      函数的定义二种定义 ①function myfunc () { console("hello"); }; ②var myfunc = function () { console ...

  4. Object C学习笔记25-文件管理(一)

    在此篇文章中简单记录一下文件管理,在Object C中NSFileManager用于管理文件已经路径.在Object C中的文件路径可以是相对路径也可以是绝对路径.斜线“/”开头,斜线实际上就是一个目 ...

  5. .net,微软,薪资及其他

    很久没在博客园上写些东西,因为我的确没有什么技术上面新奇的心得和大家分享,园子里面的文章页没啥看的,基本就是看一下业界新闻,因为这里面99%的东西没什么看头,更像是个人技术笔记汇总. 我从07年从de ...

  6. 第五次课堂总结x

    一.知识点: 1.while语句 循环体语句:           while语句里的表达式可以是任何合法的表达式,循环体则只可以表达一条语句. while的循环体语句需要能改变循环条件的真假条件. ...

  7. linux 查看服务器性能常用命令

    一.top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器   下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来 ...

  8. Red Hat Linux9命令行--修改补充中

    1.使用rpm工具安装应用软件:rpm   [选项]  [软件包名] 常用的参数及含义如下图所示: 2.编译安装应用软件 (1).tar.gz和.tgz使用如下的命令: [root@myhost ro ...

  9. JS建造者模式

    function getBeerById( id, callback){ _request('GET','URL'+id,function(res){ callback(res.responseTex ...

  10. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...