Channel
Test instructions: There is a M position, each position fills in a number, the number of the range is 1~n, ask at least a number of the same probability
Ideas:
The total is n^m, we ask for the probability of not having the same number as the L position * Set DP[I][J] means the number of the number of the first I, filling the J position of the scheme (to meet no l position is the same number) * DP[I][J]=DP[I-1][J]+SIGM (dp[i-1][j-k]*c[m- (J-K)] [K] ) k<=j&&k<l * is actually looking at the number of I, can not fill, fill a position, two locations ... This accumulates. * Then the final answer is (N^m-dp[1~n][m])/(N^M)
Code:
ImportJava.util.*;ImportJava.io.*;Importjava.math.*; Public classmain{StaticBiginteger[][] Dp=Newbiginteger[110][110]; StaticBiginteger[][] C=NewBIGINTEGER[110][110];//Number of combinations Public Static voidMain (String arg[]) {Scanner cin=NewScanner (NewBufferedinputstream (system.in)); for(inti=0;i<105;i++) {c[i][0]=c[i][i]=Biginteger.one; for(intj=1;j<i;j++) C[i][j]=c[i-1][j-1].add (c[i-1][j]); } intn,m,l; while(Cin.hasnext ()) {M=Cin.nextint (); N=Cin.nextint (); L=Cin.nextint (); BigInteger Tol=biginteger.valueof (N). POW (M); if(l>M) {System.out.println ("Mukyu~"); Continue; } if(L>M/2)//this time you can use the combination number to find out.{BigInteger ans=Biginteger.zero; for(inti=l;i<=m;i++) ans=ans.add (C[m][i].multiply (biginteger.valueof (N-1). Pow (M-i))); Ans=ans.multiply (biginteger.valueof (N)); BigInteger GCD=ANS.GCD (tol); System.out.println (Ans.divide (GCD)+"/"+tol.divide (GCD)); Continue; } for(inti=0;i<=n;i++) for(intj=0;j<=m;j++) {Dp[i][j]=Biginteger.zero; } dp[0][0]=Biginteger.one; for(inti=1;i<=n;i++) for(intj=1;j<=m;j++) { for(intk=0;k<l&&k<=j;k++) Dp[i][j]=dp[i][j].add (Dp[i-1][j-k].multiply (c[m-(J-K)] [K])); } BigInteger ans=Biginteger.zero; for(inti=1;i<=n;i++) ans=Ans.add (dp[i][m]); Ans=tol.subtract (ans); BigInteger GCD=ANS.GCD (tol); System.out.println (Ans.divide (GCD)+"/"+tol.divide (GCD)); } }}
View Code
"Probability dp" ZOJ 3380 patchouli ' s Spell Cards