标签:
#include<cstdio> double p[25],ans[25]; int n,r,vis[25]; void dfs(int k,int count) { if(count==r){ double tem=1; for(int i=1;i<=n;i++){ if(vis[i]) tem *= p[i]; else tem *= (1-p[i]); } ans[0]+=tem; for(int i=1;i<=n;i++) if(vis[i]) ans[i]+=tem; } else{ for(int i=k+1;i<=n;i++){ vis[i]=1; dfs(i,count+1); vis[i]=0; } } } int main() { int t=0; while(scanf("%d%d",&n,&r)){ if(n==0&&r==0) break; t++; printf("Case %d:\n",t); for(int i=0;i<25;i++){ ans[i]=0; vis[i]=0; } for(int i=1;i<=n;i++) scanf("%lf",&p[i]); dfs(0,0); for(int i=1;i<=n;i++) printf("%.6lf\n",ans[i]/ans[0]); } return 0; }
UVa11181 - Probability|Given(离散条件概率)
标签:
原文地址:http://blog.csdn.net/a197p/article/details/45456939