Description

As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probabilityP of getting caught. They feel that he is safe enough if the banks he robs together give a probability less than P.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains a real number P, the probability Harry needs to be below, and an integer N (0 < N ≤ 100), the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj (0 < Mj ≤ 100) and a real number Pj . Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj. A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.

Output

For each case, print the case number and the maximum number of millions he can expect to get while the probability of getting caught is less than P.

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

Case 1: 2

Case 2: 4

Case 3: 6

 
题意:一个人去抢银行,输入它被抓的概率(P)和银行的个数(N),接下来输入每个银行的钱和被抓的概率....
求这个人可以不被抓最多可以抢钱抢到多少....
 
 
解题思路:  
       既然是求他不被抓又抢到的钱最多,那么就是求他不被抓的概率中抢到的钱最多的...
      那d[j]表示他不被抓的概率,j表示抢到的钱
        d[j]=max(d[j],d[j-N[i]]*(1-P[i]))
      这里的N[i]表示银行里的钱,P[i]表示被抓概率.
      
      求出他抢到的钱不被抓的概率后,只要循环找到满足dp[j]>=1-p的j就好了(这里倒过来循环方便寻找)
 
 
 
代码如下:
 
 
 #include <stdio.h>
#include <string.h>
int N[];
double P[],d[];
double max(double a,double b)
{
return a>b?a:b;
}
int main()
{
int T,c=;
scanf("%d%",&T);
while(T--)
{
c++;
int n,total=;
double p;
memset(d,,sizeof(d));
d[]=;
scanf("%lf%d",&p,&n);
for(int i=; i<n; i++)
{
scanf("%d%lf",&N[i],&P[i]);
total+=N[i];
} for(int i=;i<n;i++)
{
for(int j=total;j>=N[i];j--)
{
d[j]=max(d[j],d[j-N[i]]*(-P[i]));
//printf("%d %lf\n",j,d[j]);
}
}
for(int i=total;i>=;i--)
{
// printf("%lf %d\n",d[i],i);
if(d[i]>=-p)
{
printf("Case %d: %d\n",c,i);
break;
}
}
}
return ;
}

第六周 N题的更多相关文章

  1. 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

    第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...

  2. hdu 4548 第六周H题(美素数)

    第六周H题 - 数论,晒素数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   De ...

  3. Codeforces 559A 第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  4. 第六周 E题 期望.....

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  5. HDU 1465 第六周L题

    Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  ...

  6. HDU 1405 第六周 J题

    Description Tomorrow is contest day, Are you all ready?  We have been training for 45 days, and all ...

  7. HDU 2669 第六周 I题

    Description The Sky is Sprite.  The Birds is Fly in the Sky.  The Wind is Wonderful.  Blew Throw the ...

  8. 第六周O题(等边三角形个数)

    O - 计数 Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Descripti ...

  9. HDU1465 第六周L题(错排组合数)

    L - 计数,排列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descrip ...

随机推荐

  1. vb.net详解MDI窗体操作方法

    MDI窗体可以避免打开窗体的时候被无数个子窗体困扰,我将为大家一一的介绍一下vb.net中MDI窗体的操作方法 一.如何创建MDI窗体? 1.创建mdi主窗体 新建建立一个默认空白的Windows应用 ...

  2. 【MongoDB】MongoDB VS SQL数据库

    MongoDB和SQL数据库都能满足数据库的基本功能:1.有组织的存放数据:2.按照需求查询数据 传统的SQL数据库(e.g.Oracle, MySQL) 对表的运用不够灵活,横向扩展不太容易,而它的 ...

  3. PHP使用外部命令导出数据库,备份到服务器并下载到本地

    <?php // $dumpFileName目录要有可写权限 $DbHost = 'localhost'; $DbUser = 'root'; $DbPwd = '123456'; $DbNam ...

  4. mac jdk设置

    mac系统一般默认会安装jdk 1.6,路径为/System/Library/Java/JavaVirtualMachines/1.6.0.jdk,此Jdk为系统默认jdk; 但某些框架/应用要求jd ...

  5. Windows添加在此处打开命令CMD

    打开rededit在:HKEY_CLASS_ROOT > * > shell >下面新建一个项CMD 在CMD中新建两个字符串 一个是默认,值为 @shell32.dll,- 另外一 ...

  6. codeforces 590B B. Chip 'n Dale Rescue Rangers(二分+计算几何)

    题目链接: B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabyte ...

  7. UIActivityIndicatorView的使用方法(旋转动画)

    - (void)viewDidLoad { [super viewDidLoad]; //创建UIActivityIndicatorView并设置样式:WhiteLarge为37 * 37,Gray和 ...

  8. Java作业 输入圆的半径计算输出圆的周长和面积

    package text1; import java.util.Scanner; public class text11 { public static void main(String[] args ...

  9. Discuz!图片查看插件(支持鼠标缩放、实际大小、旋转、下载)

    Discuz!图片查看插件(支持鼠标缩放.实际大小.旋转.下载) 图片查看是网站中的常用功能,用于展示详细的图片.在discuz图片插件的基础上进行了改造,因此这篇文章主要从以下几个方面来讨论图片查看 ...

  10. Table of Contents - HttpClient

    HttpClient 4.3.5 Getting Started HttpClient 简单示例 Fundamentals Request Execution HTTP Request & H ...