"Probability dp" ZOJ 3380 patchouli ' s Spell Cards

Source: Internet
Author: User

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&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.