题解:
由题意得
需要运用:
C(m,n)=exp(logC(m,n))
f[0]=0; for(int i=1; i<=400002; i++) f[i]=f[i-1]+log(i*1.0); double logC(int m,int n) { return f[m]-f[n]-f[m-n]; }
#include<stdio.h> #include<math.h> double f[400005]; double logC(int m,int n) { return f[m]-f[n]-f[m-n]; } int main() { f[0]=0; int test=0,n; double p,q,ans; for(int i=1;i<=400002;i++) f[i]=f[i-1]+log(i*1.0); while(scanf("%d %lf",&n,&p)!=EOF) { test++; q=1-p; ans=0; for(int k=0;k<=n;k++) ans+=(n-k)*(exp(logC(n+k,k)+(n+1)*log(q*1.0) +k*log(p*1.0))+exp(logC(n+k,k)+(n+1)*log(p*1.0)+k*log(q*1.0))); printf("Case %d: %.6lf ",test,ans); } return 0; }