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. 《Cortex-M0权威指南》之Cortex-M0技术综述

    转载请注明来源:cuixiaolei的技术博客 Cortex-M0 处理器简介 1. Cortex-M0 处理器基于冯诺依曼架构(单总线接口),使用32位精简指令集(RISC),该指令集被称为Thum ...

  2. [原创] Web UI 自动化日期控件的处理

    序 在构建自动化套件的过程中,日期操作是一件很重要也很频繁的事情.有的日期控件的div层级结构复杂,同一个类型的日期控件在多个子系统中的表现形式也大相径庭.多数工程师为了避免重复的工作,会封装抽象一个 ...

  3. 在Firefox中通过AJAX跨域访问Web资源---

    一.解决在firefox中无法跨域访问的问题 AJAX从本质上讲就是命名用XMLHttpRequest组件来向服务端发送HTTP请求,请接收相应信息.至于成功接收到响应信息后的操作,就和普通的Web客 ...

  4. (转)JavaScript 中对变量和函数声明的“提前(hoist)”

    变量声明“被提前” JavaScript 的语法和 C .Java.C# 类似,统称为 C 类语法.有过 C 或 Java 编程经验的同学应该对“先声明.后使用”的规则很熟悉,如果使用未经声明的变量或 ...

  5. Linux Bash Shell学习笔记

    参数扩展: 1.被名称引用的参数称作变量2.被数字引用的参数称作位置参数3.被特定符号引用的参数具有特殊的含义和用途,被称作Bash的特殊内部变量引用. 基本参数扩展:字符$会引导参数扩展.大括号是可 ...

  6. 获取数组排序后的index算法实现

    需求: 一个数组var arr = [4,7,2,9],排序后的新数组var newArr = [2,4,7,9]或者[9,7,4,2] 我们要得到的是排序后元数组的每一项在新数组中的位置所构成的数组 ...

  7. BI中PowerDesigner建模

    PowerDesigner下载: http://pan.baidu.com/share/link?shareid=296749&uk=1479845243

  8. hdu 2121 , hdu 4009 无定根最小树形图

    hdu 2121 题目:给出m条有向路,根不确定,求一棵最小的有向生成树. 分析:增加一个虚拟节点,连向n个节点,费用为inf(至少比sigma(cost_edge)大).以该虚拟节点为根求一遍最小树 ...

  9. 非常棒的 「Sublime Text 配色/主题」与「编程字体」

    *标有 CT 的是配色 **主题中调用的字体和相配套的Sublime主程序图标可访问GitHub获取 Afterglow https://github.com/YabataDesign/aftergl ...

  10. 教你21天学会C++ (有图有真相)

    这张图,是在一位有十多年开发经验的资深前辈博客里看到的,觉得很有趣,分享之~ 这位大神的博客是:http://coolshell.cn 理论是可行的,当你刚开始学习C++,到第21天的时候出门千万要小 ...