Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

xx

Posted by zhangxiao1124 at 2008-05-04 21:54:11 on Problem 3558
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator