Zoj 3344 Card Game
Test instructions
Write n A number (the number range is 1~n, and different) cards scrambled order, and then placed in the box numbered 1~n, the action of each round is as follows: First remove the card from the remaining numbered box, the multiplication write k, if the K box has not been opened, then continue to open the K box, Take out the card ... Until no box can be opened. Take the last box for the winner.
EZ wants to know the probability that he will win the game within the M-wheel.
Limit:
1 <= n <= 50; 1 <= k <= N
Ideas:
The first class of Stirling numbers, EZ only wins when the number of copies is odd and the number of copies is less than M.
N=50, use a large number of java.
/*zoj 3344 Card Game Test instructions: the cards that write n numbers (numbers ranging from 1~n to each other) are scrambled and placed in a box numbered 1~n, and each wheel moves as follows: First take the card from the remaining numbered box, and the multiplication piece says K, If the K box has not been opened yet, continue to open the K box and remove the card ... Until no box can be opened. Take the last box for the winner. EZ wants to know the probability that he will win the game within the M-wheel. Limit: 1 <= n <= 50; 1 <= k <= N idea: The first class of Stirling numbers, EZ only wins when the number of copies is odd and the number of copies is less than M. N=50, use a large number of java. */import java.math.biginteger;import java.security.guardedobject;import java.util.*;p ublic class Main{static biginteger[][] sti=new biginteger[55][55];static void get_sti (int n) {for (int i=1;i<=n;++i) {sti[i][0]= Biginteger.zero;sti[i][i]=biginteger.one;} for (int i=2;i<=n;++i) {for (int j=1;j<i;++j) {sti[i][j]=biginteger.valueof (i-1). Multiply (Sti[i-1][j]). Add (STI [I-1] [j-1]);}}} static void print (int n) {for (int. i=1;i<=n;++i) {for (int j=1;j<=i;++j) {System.out.print (sti[i][j]+ "");} System.out.println ("");}} static void Gao (int n,int k) {BigInteger fz,fm,d;fz=fm=biginteger.zero;for (int i=1;i<=n;++i) {if (I%2==1 && i <=k) Fz=fz.add (Sti[n][i]); Fm=fm.add (Sti[n][i]);} D=FZ.GCD (FM); System.out.pRintln (Fz.divide (d) + "/" +fm.divide (d)); public static void Main (String args[]) {get_sti (50); Scanner in=new Scanner (system.in); int N,k;while (In.hasnext ()) {n=in.nextint (); K=in.nextint (); Gao (n,k);}}
Zoj 3344 Card Game