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. 50个C++源码学习网站

    C/C++是最主要的编程语言.这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码 .这份清单提供了源代码的链接以及它们的小说明.我已尽力包括最佳的C/C++源代码的网站.这不是一个完整的 ...

  2. 1030. Travel Plan (30)

    时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the dista ...

  3. UVA 725

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  4. (转)Qt Model/View 学习笔记 (七)——Delegate类

    Qt Model/View 学习笔记 (七) Delegate  类 概念 与MVC模式不同,model/view结构没有用于与用户交互的完全独立的组件.一般来讲, view负责把数据展示 给用户,也 ...

  5. 后台启动mysql ,redis

    mysqld_safe --user=mysql & redis.conf daemonize no修改为daemonize yes

  6. OC 数据类型之间的转换方法

      NSNumber转NSString: 假设现有一NSNumber的变量A,要转换成NSString类型的B 方法如下: NSNumberFormatter* numberFormatter = [ ...

  7. jquery bind()方法与live()方法的区别

    jquery bind() 方法和 live() 方法都可以绑定元素事件. <!DOCTYPE html> <html> <head> <meta chars ...

  8. Shiro 缓存失效以后的一个问题

    shiro 1.2.2和1.2.3 为shiro设置了缓存,但是当服务器运行几个小时后,页面判断 <shiro:hasPermission name="admin"> ...

  9. protobuf 向前兼容向后兼容

    http://blog.163.com/jiang_tao_2010/blog/static/12112689020114305013458/ 不错的protobuf.. protobuf的编码方式: ...

  10. 团体程序设计天梯赛-练习集L1-024. 后天

    L1-024. 后天 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 如果今天是星期三,后天就是星期五:如果今天是星期六,后天就 ...