Robberies

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

Total Submission(s): 16565 Accepted Submission(s): 6087

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

#include <iostream>
#include <set>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int MAX=101000;
typedef pair<int ,double >pr;
typedef long long LL;
double Dp[11000];
pr a[110];
double s;
int n,sum;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf %d",&s,&n);
sum=0;
for(int i=0;i<n;i++)
{
scanf("%d %lf",&a[i].first,&a[i].second);
sum+=a[i].first;
}
memset(Dp,0,sizeof(Dp));
Dp[0]=1;
for(int i=0;i<n;i++)//将金钱作为重量概率作为价格进行01背包
{
for(int j=sum;j>=a[i].first;j--)
{
Dp[j]=max(Dp[j],Dp[j-a[i].first]*(1-a[i].second));
}
}
int ans=0;
s=1-s;
for(int i=sum;i>0;i--)//要求是被抓住的概率小于s,就是不被抓住的概率大于(1-s)
{
if(s<Dp[i])
{
ans=i;
break;
}
}
printf("%d\n",ans);
}
return 0;
}

Robberies(简单的01背包 HDU2955)的更多相关文章

  1. HDU 2602 (简单的01背包) Bone Collector

    很标准的01背包问题 //#define LOCAL #include <algorithm> #include <cstdio> #include <cstring&g ...

  2. Robberies hdu 2955 01背包

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

  3. HDU 2955 Robberies抢劫案(01背包,变形)

    题意:要抢劫,但是抢每个银行都有被抓的概率,问在低于规定的被抓概率情况下最多能抢到多少钱. 输入:第一行为T,表示共T个测试例子.每个例子的第一行给出一个浮点数P,是规定被抓的概率上限.第一行还有一个 ...

  4. 【hdu2955】 Robberies 01背包

    标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...

  5. POJ 3624 Charm Bracelet 简单01背包

    题目大意:有n件珠宝,每个珠宝的魅力值为v,重量为w,求在重量不超过m的情况下能达到的最大魅力值. 题目思路:简单的01背包,由于二维数组会超内存所以应该压缩成一维数组. dp[i][j],表示选取i ...

  6. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  7. 【HDU 3810】 Magina (01背包,优先队列优化,并查集)

    Magina Problem Description Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of ...

  8. HDU 1203 I NEED A OFFER! 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 解题思路:简单的01背包,用dp[i]表示花费不超过i时的最大可能性 状态转移方程 dp[i]= ...

  9. HDU -1864最大报销额(01背包)

    这道题属于简单的01背包,但是背包问题还算简单,就是前面的细节处理的时候要注意,题意大致说了三条限制吧 1. 只有a, b, c 三种类型的发票可以报销,其它的一律不报销 2. 物品单项的报销额不超过 ...

随机推荐

  1. WebService之Axis2 后续(6)~(10)目录

    WebService大讲堂之Axis2(6):跨服务会话(Session)管理 WebService大讲堂之Axis2(7):将Spring的装配JavaBean发布成WebService WebSe ...

  2. Lintcode: Matrix Zigzag Traversal

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-or ...

  3. JavaScript----marquee滚动标签 图片无缝滚动 插入百度地图

    页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...

  4. Ios(ipad iphone) 支持字体一览

    Font Name : ThonburiFont Name : Snell RoundhandFont Name : Academy Engraved LETFont Name : AvenirFon ...

  5. JAVA JDBC连接 SQLServer2012 连接失败 端口号错误

    SQLServer2012的SQL Sever 网络配置 我有4个 SQLEXPRESS的协议 SQLSERVER2008的协议 MSSQLSERVER的协议 SQLSERVER2012的协议 他们都 ...

  6. 传递闭包(Floyd+bellman-Fold POJ1932)

    传递闭包 在一个有向(无向)连通图中,如果节点i与k联通,k与j联通,则i和j联通,传递闭包就是把所有传递性的节点求出来,之后就知道了任意两个节点的连通性,只需枚举节点的联通情况即可,无需考虑最短路径 ...

  7. sqlserver 存储过程 以及统计整个数据库数据

    drop proc test 删除存储过程 go  用于在 SSMS 和 SQLCMD 中将其之前的 T-SQL 语句作为一个批处理提交给 SQL Server 实例.GO 不是 T-SQL 语句,只 ...

  8. HDU 4833 Best Financing(DP)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[ ...

  9. struts请求基本类型参数接收

    01:导包,web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version ...

  10. 经过本人 6 年.net 工作经验证明 .net 工资确实比 Java 低

    很久没有逛博客园了,很久没有出来吐槽了.怎么呢?生活压力大,就需要找地方吐槽. 排版不怎么好,文笔不怎么好,可以看出我不是雇佣的写手. 工作到今夏,已经有6个年头了,一直使用着.net技术,但是最近工 ...