第五十八题 UVa 11181 Probability|Given

116 篇文章 1 订阅
75 篇文章 0 订阅

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

题目分析
条件概率:P(B|A)=P(A∩B)/P(A)
用样例解释就是:P(B)= 0.10.20.7+0.10.30.8+0.20.30.9
P(A∩B)=0.10.20.7+0.10.30.8。。
得到P(A|B)

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
double p[22],fac,Ans[22];
int n,r;
bool vis[22];
void DFS(int step,double sum,int cnt){
	if(cnt>r) return;
	if(step==n+1){
		if(cnt==r){
			fac+=sum;
			for(int i=1;i<=n;++i)
				if(vis[i]) Ans[i]+=sum;
		}
		return ;
	}
	vis[step]=true;
	DFS(step+1,sum*p[step],cnt+1);
	vis[step]=false;
	DFS(step+1,sum*(1-p[step]),cnt);
}

int Main(){
	scanf("%d%d",&n,&r);
	for(int i=1;i<=n;++i) scanf("%lf",&p[i]);
	DFS(1,1.0,0);
	for(int i=1;i<=n;++i) printf("%.3lf\n",Ans[i]/fac);
	return 0;
}
int Aptal_is_My_Son=Main();
int main(int argc,char *argv[]){ ; }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据给出的引用内容,问是关于函数"predict_probability()"的参数数量问。错误提示显示函数期望2个位置参数,但实际给出了3个参数。 根据引用,定义了一个(3,1)的矩阵变量X。根据引用,这些参数只是在物理空间中定义,还没有通过session执行。根据引用,实现了一个函数Y=WX+b的TensorFlow版本,其中W和X是随机矩阵,b是随机向量,它们的维度分别为(4,3)、(3,1)和(4,1)。 根据给出的信息,可以推测到函数"predict_probability()"是一个与矩阵W、X和b相关的函数,可能是用于预测概率的函数。而问提示中的错误显示给出了3个参数,但函数期望的参数数量只有2个。 为了解决这个问,可以检查函数"predict_probability()"的定义并确保它只接受期望的参数数量。另外,还需要检查函数在调用时是否正确地传递了参数。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [吴恩达Coursera深度学习课程 course2-week3 超参数调试和Batch Norm及框架 作业](https://blog.csdn.net/zongza/article/details/83344053)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值