集训第六周 数学概念与方法 概率 N题

N - 概率

Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

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,他就会很安全,否则就一定会被抓。

于是哈利波特去调查了一下,记录每个银行的存钱量和被抓的风险,要求你计算他最多能抢多少钱

先转化一下:改限制为不被抓的概率大于等于(1-P),再将这个问题转化为背包01问题

dp(i)代表抢i枚大钱不被抓的概率

dp (i)=max { dp ( i - a[j] ) *( 1- p[j] ) , dp[i] }  (i--0~所有银行的钱,j遍历所有银行)

#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=110;
double dp[maxn*maxn],P,b[maxn];
int n,a[maxn],sum,ca=1;
void Init()
{
    cin>>P>>n;
    sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        sum+=a[i];
    }
    memset(dp,0,sizeof(dp));
}

void Work()
{
    dp[0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=sum;j>=a[i];j--)
        {
            dp[j]=max(dp[j-a[i]]*(1-b[i]),dp[j]);
        }
    }
}

void Print()
{
    cout<<"Case "<<ca++<<": ";
    for(int i=sum;i>=0;i--)
    {
        if(dp[i]>(1-P))
        {
            cout<<i<<endl;
            break;
        }
    }
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
     Init();
     Work();
     Print();
    }
    return 0;
}
时间: 2024-08-28 23:07:32

集训第六周 数学概念与方法 概率 N题的相关文章

集训第六周 数学概念与方法 概率 F题

Submit Status Description Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two peopl

集训第六周 数学概念与方法 概率 数论 最大公约数 G题

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into

集训第六周 数学概念与方法 数论 筛素数 G题

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

集训第六周 数学概念与方法 UVA 11181 条件概率

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概率会给出,问这一群人去买东西,第i个人属于r之中的概率是多少 思路:首先得了解什么是条件概率. 条件概率:事件A在事件B成立的基础上再成立的概率,公式为:P(A|B)=P(A*B)/P(B) 可以照着题目案例1进行分析: 输入 0.10 0.20 0.30 输出 0.413043 0.739130

集训第六周 数学概念与方法 UVA 11722 几何概型

---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[s1,s2]的时间段停留在同一个站点w分钟,问两辆火车能够在这个站点相遇的概率. 思路,枚举每一种情况,把两辆火车的相交区间画出来,然后求都在这个区间的概率 #include"iostream" #include"cstdio" #include"cmath&

集训第六周 数学概念与方法 计数 排列 L题

Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不

集训第六周 数学概念与方法 数论 线性方程 I题

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

集训第六周 古典概型 期望 D题 Discovering Gold 期望

Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice a

集训第六周 E题

E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once.