N friends go to the local super market together. The probability of their buying something from the
market is p1, p2, p3, . . . , pN respectively. After their marketing is finished you are given the information
that exactly r of them has bought something and others have bought nothing. Given this information
you will have to find their individual buying probability.
Input
The input file contains at most 50 sets of inputs. The description of each set is given below:
First line of each set contains two integers N (1 ≤ N ≤ 20) and r (0 ≤ r ≤ N). Meaning of N and
r are given in the problem statement. Each of the next N lines contains one floating-point number pi
(0.1 < pi < 1) which actually denotes the buying probability of the i-th friend. All probability values
should have at most two digits after the decimal point.
Input is terminated by a case where the value of N and r is zero. This case should not be processes.
Output
For each line of input produce N +1 lines of output. First line contains the serial of output. Each of the
next N lines contains a floating-point number which denotes the buying probability of the i-th friend
given that exactly r has bought something. These values should have six digits after the decimal point.
Follow the exact format shown in output for sample input. Small precision errors will be allowed. For
reasonable precision level use double precision floating-point numbers.
Sample Input
3 2
0.10
0.20
0.30
5 1
0.10
0.10
0.10
0.10
0.10
0 0
Sample Output
Case 1:
0.413043
0.739130
0.847826
Case 2:
0.200000
0.200000
0.200000
0.200000
0.200000

题意:  给你n个人买东西的概率p[i] ,   问你恰好有R个人买了东西,第i个人买东西的概率

题解: N的范围小  20

暴力搜索所有情况就好了

   注意答案是  ans[i]/p   p为n个人与r个人买了东西的概率

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; double ans[N],p[N];
int n;
double dfs(int cnt,int r,double pi) {
if(cnt > n)
if(r) return ;
else return pi;
double sum = ;
if(r) {
sum += dfs(cnt+,r-,pi*p[cnt]);
ans[cnt] += sum;
}
sum += dfs(cnt+,r,pi*(-p[cnt]));
return sum;
}
int main() {
int cas = ,r;
while(~scanf("%d%d",&n,&r)) {
if(n==&&r==) break;
for(int i=;i<=n;i++) scanf("%lf",&p[i]);
mem(ans);
printf("Case %d:\n", cas++);
double p = dfs(,r,);
for(int i=;i<=n;i++)
printf("%.6f\n", ans[i]/p);
}
return ;
}

代码

UVA 11181 dfs 概率的更多相关文章

  1. 紫书 例题 10-11 UVa 11181(概率计算)

    这道题不能凭感觉做了.要套公式 r个人买了东西叫事件E, 第i个人买东西的概率叫做事件Ei 求得是P(E|Ei), 则P(E|Ei)= P(E|Ei)/ P(E) 那么P(E)可以枚举求得, 用递归求 ...

  2. uva 11181 - Probability|Given(概率)

    题目链接:uva 11181 - Probability|Given 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],当有r个人买东西的时候,第i个人恰好买东西的概率. 解题思路 ...

  3. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  4. 概率论 --- Uva 11181 Probability|Given

    Uva 11181 Probability|Given Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  5. UVA - 11181 数学

    UVA - 11181 题意: n个人去买东西,其中第i个人买东西的概率是p[i],最后只有r个人买了东西,求每个人实际买了东西的概率 代码: //在r个人买东西的概率下每个人买了东西的概率,这是条件 ...

  6. UVA 11181 Probability|Given (离散概率)

    题意:有n个人去商场,其中每个人都有一个打算买东西的概率P[i].问你最后r个人买了东西的情况下每个人买东西的概率 题解:一脸蒙蔽的题,之前的概率与之后的概率不一样??? 看了白书上的题解才知道了,其 ...

  7. UVa 11181 - Probability|Given(条件概率)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVa 11181 (条件概率) Probability|Given

    题意: 有n个人买东西,第i个人买东西的概率为Pi.已知最终有r个人买了东西,求每个人买东西的概率. 分析: 设事件E为r个人买了东西,事件Ei为第i个人买了东西.所求为P(Ei|E) = P(EiE ...

  9. UVA 11021 - Tribles(概率)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...

随机推荐

  1. hdu 5264 pog loves szh I

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5264 pog loves szh I Description Pog has lots of stri ...

  2. golang的哪些坑爷事: package实践

    在golang中package是个困惑的概念, 特别是package还可以与folder不同名, 委实让我恶心了一把. 关于golang的package的最佳实践: package is folder ...

  3. JavaScript 字符串处理详解【转自:http://www.cnblogs.com/mondLei/p/4096855.html】

    一.创建字符串       创建一个字符串,将一组字符串用引号包起来,将其赋值给一个字符串变量. var JsStr="Hello,JavaScript String!"; 二.字 ...

  4. UISlider swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  5. 使用Groovy构建自己的脚本环境

    场景 在进行Web服务端开发的时候,发布前通常需要测试一遍.对于一个大一点的项目,最好的办法是写个自动化测试程序. 以Groovy为例,写测试代码之前通常的有如下几个操作 引用相关的类库 import ...

  6. C# 微信公众号

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. <梦断代码>读后感2

    <梦断代码>这本书读了一半,我的心情久久不能平静. 为什么好软件如此难做?这是我本人,我想也是很多人都在苦苦思索的一个问题,虽然没有人能有完全确定的答案,但通过书中的记述,和个人思考,还是 ...

  8. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  9. 如何在Android模拟器上安装apk文件

    1.运行SDK Manager,选择模拟器,并运行模拟器 SDK Manager应用 2.将需要安装的apk文件复制到platform-tools目录下(默认在:D:\tools\android\ad ...

  10. Jquery结合Ztree生成树

    尊重作者,附原文链接:http://my.oschina.net/u/2472104/blog/529055 Ztree的api http://www.ztree.me/v3/api.php Ztre ...