Expect, $DP $.
Set $dp[i]$ indicates the expected number of $i$ numbers that have been present. In this state, if you cast again, there are two possibilities, that is, $i+1$ numbers and $i$ numbers.
So $DP [i]=dp[i]*i/n+dp[i+1]* (n-i)/n+1$, i.e. $dp[i]=dp[i+1]+n/(n-i) $, $DP [n]=0$, Launch $dp[0]$.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-6;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} Template<classT>inlinevoidRead (T &x) { Charc =GetChar (); X=0; while(!isdigit (c)) C =GetChar (); while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();}}intT,n;Doubledp[100010];intMain () {scanf ("%d", &t);intcas=1; while(t--) {scanf ("%d",&N); Dp[n]=0; for(inti=n-1; i>=0; i--) {Dp[i]=dp[i+1]+1.0*n/(ni); } printf ("Case %d:%lf\n", cas++,dp[0]); } return 0;}
Lightoj 1248 Dice (III)