UVA 11181 dfs 概率
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 概率的更多相关文章
- 紫书 例题 10-11 UVa 11181(概率计算)
这道题不能凭感觉做了.要套公式 r个人买了东西叫事件E, 第i个人买东西的概率叫做事件Ei 求得是P(E|Ei), 则P(E|Ei)= P(E|Ei)/ P(E) 那么P(E)可以枚举求得, 用递归求 ...
- uva 11181 - Probability|Given(概率)
题目链接:uva 11181 - Probability|Given 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],当有r个人买东西的时候,第i个人恰好买东西的概率. 解题思路 ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- 概率论 --- Uva 11181 Probability|Given
Uva 11181 Probability|Given Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...
- UVA - 11181 数学
UVA - 11181 题意: n个人去买东西,其中第i个人买东西的概率是p[i],最后只有r个人买了东西,求每个人实际买了东西的概率 代码: //在r个人买东西的概率下每个人买了东西的概率,这是条件 ...
- UVA 11181 Probability|Given (离散概率)
题意:有n个人去商场,其中每个人都有一个打算买东西的概率P[i].问你最后r个人买了东西的情况下每个人买东西的概率 题解:一脸蒙蔽的题,之前的概率与之后的概率不一样??? 看了白书上的题解才知道了,其 ...
- UVa 11181 - Probability|Given(条件概率)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11181 (条件概率) Probability|Given
题意: 有n个人买东西,第i个人买东西的概率为Pi.已知最终有r个人买了东西,求每个人买东西的概率. 分析: 设事件E为r个人买了东西,事件Ei为第i个人买了东西.所求为P(Ei|E) = P(EiE ...
- UVA 11021 - Tribles(概率)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...
随机推荐
- MySQL 触发器简单实例
~~语法~~ CREATE TRIGGER <触发器名称> --触发器必须有名字,最多64个字符,可能后面会附有分隔符.它和MySQL中其他对象的命名方式基本相象.{ BEFORE | ...
- jquery.form的使用
插件API http://malsup.com/jquery/form/#api Jquery.form.js是支持文件异步上传的插件,jq插件自然基本前提当然是要引用Jquery.js 1.0 基本 ...
- Sliverlight Slide 的左右滑动
private void btnPrev_Click(object sender, RoutedEventArgs e) { scrollRule = (scrollRule-) >= ?(sc ...
- JSON数组操作
在jquery中处理JSON数组的情况中遍历用到的比较多,但是用添加移除这些好像不是太多. 今天试过json[i].remove(),json.remove(i)之后都不行,看网页的DOM对象中好像J ...
- Rstdio中更换R版本
1.打开Rstdio,选择Tool --> Global Options.
- 霍夫变换(hough transform)
x-y轴坐标:y=kx+b k-b轴坐标:b=-xk+y θ-r轴坐标:
- Android实现AppWidget、Broadcast动态注册
Android实现AppWidget.Broadcast动态注册 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 主界面可以编辑广播的信息,点 ...
- Asp.Net Web API开发微信后台
如果说用Asp.Net开发微信后台是非主流,那么Asp.Net Web API的微信后台绝对是不走寻常路. 需要说明的是,本人认为Asp.Net Web API在开发很多不同的请求方法的Restful ...
- Notes of the scrum meeting(11/3)
meeting time:19:30~20:00p.m.,November 3th,2013 meeting place:20号公寓楼前 attendees: 顾育豪 ...
- Windows下查看8080进程及结束进程命令
Windows下查看进程及结束进程命令 1)查看占用8080端口的进程号 >netstat –aon | findstr “8080” 结果:TCP 0.0.0.0:8080 ...