Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
xx#include<iostream> using namespace std; #define maxn 500 double p,pow_c[maxn],pow_uc[maxn]; int n; double f[maxn],g[maxn]; double C(int n,int m) { double res=1.0; int i; for (i=1; i<=m; i++) res*=(double)(n+1-i),res/=(double)i; return res; } int main() { int i,j; scanf("%d%lf",&n,&p); pow_uc[0]=1; for (i=1; i<=n*n; i++) pow_uc[i]=pow_uc[i-1]*(1-p); f[1]=1; for (i=2; i<=n; i++) { for (j=0; j<i-1; j++) g[i]+=C(i-1,j)*f[j+1]*pow_uc[(i-j-1)*(j+1)]; f[i]=1-g[i]; } printf("%.8lf\n",f[n]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator