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. 解决本地tomcat服务器内存不足问题

    2014-6-25 9:47:48 org.apache.coyote.http11.Http11Processor process严重: Error processing requestjava.l ...

  2. 【Origin】答友朋关切书

    发烧感冒脑袋疼, 剃了短毛不威风: 莫再问我有何事, 躺下一觉到天明. --作于二零一五年七月二十七日

  3. csuoj 1335: 高桥和低桥

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1335 1335: 高桥和低桥 Time Limit: 1 Sec  Memory Limit: 1 ...

  4. XML节点名称中有小数点处理(deal with dot)导致使用xpath时报错解决方法

    <?xml version="1.0"?> <ModifyFiles> <_Layout.cshtml>123456</_Layout.c ...

  5. php 警告

    php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...

  6. android复习第二天------布局

    1,在4,0版本前一共有五种布局,且都是ViewGroup的子类分别是 RelativeLayout(相对),AbsoluteLayout(绝对),LinearLayout(线性),FrameLayo ...

  7. paper 76:膨胀、腐蚀、开、闭运算——数字图像处理中的形态学

    膨胀.腐蚀.开.闭运算是数学形态学最基本的变换.本文主要针对二值图像的形态学膨胀:把二值图像各1像素连接成分的边界扩大一层(填充边缘或0像素内部的孔):腐蚀:把二值图像各1像素连接成分的边界点去掉从而 ...

  8. unable to connect to the virtual device Genymotion 神器启动问题

    截图: 解决方法:win7以上用户在桌面找到:网络--右键(属性)--更改适配器设置--VirtualBox Host-Only Network--属性--双击:Internet 协议版本4(TCP/ ...

  9. 03---Net基础加强

    多态---虚方法    (子类可以选择重写或者不重写) class Program { static void Main(string[] args) { Chinese cn1 = new Chin ...

  10. centos的用户管理相关命令所在的包

    用户管理命令是指:useradd userdel  groupadd groupdel 这些 这些命令出自一个叫 shadow-utils 的包. 对于配置文件 /etc/shadow ,则来自一个叫 ...