Robberies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7351    Accepted Submission(s): 2762 
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
 

Source
 

Recommend
gaojie
// 好吧、我对概率真的好弱智  我开始居然是把概率相加了、、、
// 这种情况、为了避开繁杂的讨论 就是利用补集来算了、对立算起来真心更清爽、然后就是O 1 背包了
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
double dp[];
int M[];
double p[];
#define epx 0.000000001
int main()
{
int T,n,V;
double P;
int i,j,k;
scanf("%d",&T);
while(T--){
scanf("%lf %d",&P,&n);
V=;
for(i=;i<=n;i++)
{
scanf("%d %lf",&M[i],&p[i]);
V+=M[i];
}
for(i=;i<=V;i++)
dp[i]=;
dp[]=;
for(i=;i<=n;i++)
for(j=V;j>=M[i];j--){
if(dp[j]<dp[j-M[i]]*(-p[i]))
dp[j]=dp[j-M[i]]*(-p[i]);
}
P=-P;
for(i=V;i>;i--)
if(dp[i]>=P)
break;
printf("%d\n",i);
} return ;
}

hdu 2955 Robberies的更多相关文章

  1. HDU 2955 Robberies 背包概率DP

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

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

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

  3. HDU 2955 Robberies(DP)

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

  4. hdu 2955 Robberies (01背包)

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

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

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

  6. Hdu 2955 Robberies 0/1背包

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

  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 背包DP

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

  9. HDU 2955 Robberies(01背包)

    Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...

随机推荐

  1. seo 优化 仅针对 来拍呀www.laipaiya.com(一)

    加入百度统计代码:http://tongji.baidu.com/ 查看百度统计优化分析->seo建议 对每个页面的meta标签做修改 首页 title :来拍呀 - | 折扣好房你就来拍呀 k ...

  2. MYsqli 绑定插入与查询实例

    <?php $conn = new mysqli('localhost','root','','orders'); //连接 $prepare = "insert into t100 ...

  3. go语言实现线程池

    话说真的好久没有写博客了,最近赶新项目,工作太忙了.这一周任务比较少,又可以随便敲敲了. 逛论坛的时候突发奇想,想用go语言实现一个线程池,主要功能是:添加total个任务到线程池中,线程池开启num ...

  4. iOS 基础 第一天(0804)

    OC对象的本质就是一个结构体 为什么说是个结构体? 例如:类里面声明了几个成员变量\实例变量(已添加@plublic),外部对象的指针在访问这个变量的时候是这么写的p->a 0804 注意oc的 ...

  5. 1023: [SHOI2008]cactus仙人掌图 - BZOJ

    Description如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回路 ...

  6. linux bash_profile和.bashrc区别

    经常在一些技术类的文章中提到修改bash_profile和.bashrc这两个文件,也算是使用频率比较高的两个文件吧,但实现同样一个功能,有的教程里说修改bash_profile这个文件,有的教程里却 ...

  7. linux 使用文本编辑器编写shell脚本执行权限不够

    在linux下,自己编写的脚本需要执行的时候,需要加上执行的权限 解决方式:chmod 777 test.sh

  8. linux 文件比对总结

    1. 过滤a.log的重复数据 #统计 cat datatest.log|sort|uniq -d |wc -l #放入b.log cat datatest.log|sort|uniq -d > ...

  9. jQuery 的 $("someobjectid”).event() 的绑定

    经验证,jquery 的 $("someobjectid”).event()事件绑定,如果放在某个会被重新初始化的对象里,就会被多次绑定. 如下 <div id="divID ...

  10. MSSQLServer基础04(常用函数)

    类型转换函数 CAST ( expression AS data_type) CONVERT ( data_type, expression,[style]) 对日期的转换.转换成各种国家格式的日期. ...