SPOJ - FAVDICE 简单期望

dp[0]=0;
        // rep(i,1,n) dp[i]=(double)(n-i)/n*dp[i-1]+1+(double)(i)/n*dp[i];
        // (n-i)/n dp[i]= n-i / n * dp[i-1] +1 => dp[i]=dp[i-1]+n/n-i
        rep(i,1,n-1) dp[i]=dp[i-1]+(double)n/(n-i);

ans为dp[n-1]+1

posted @ 2018-03-08 15:59  Caturra  阅读(137)  评论(0编辑  收藏  举报