Zoj 3380 patchouli's spell cards (probability DP)

Source: Internet
Author: User
Patchouli's spell cards
Time limit:7 seconds Memory limit:65536 KB

Patchouli knowledge, the unmoving Great Library, is a magician who has settled down in the scarlet dedevil mansion (). her specialty is Elemental magic employing the seven elements fire, water, wood, metal, earth, sun, and moon. so she can cast different spell cards likeWater sign "Princess Undine",Moon sign "Silent Selene"AndSun sign "Royal flare". In addition, she can combine the elements as well. So she can also cast high-level spell cards likeMetal & water sign "Mercury poison"AndFire, water, wood, metal & earth sign "Philosopher's Stones".

Assume that there areMDifferent Elements in total, each element hasNDifferent phase. patchouli can use your different elements in a single spell card, as long as these elements have the same phases. the level of a spell card is determined by the number of different elements used in it. when patchouli is going to have a fight, she will chooseMDifferent elements, each of which will have a random phase with the same probability. What's the probability that she can cast a spell card of which the level is no lessL, Namely a spell card using at leastLDifferent elements.

Input

There are multiple cases. Each case contains three integers 1 ≤M,N,L≤ 100. process to the end of file.

Output

For each case, output the probability as irequalcible fraction. If it is impossible, output "mukyu ~ "Instead.

Sample Input
 
7 6 57 7 77 8 9
Sample output
 
187/155521/117649mukyu ~
References

Author:Wu, zejun
Source:ACM × touhou
Contest:Zoj monthly, August 2010.

 

 

 

/*
* Zoj 3380
* Meaning: There are m positions, and each position is filled with a number. The value range is 1 ~ N: The probability that at least one number of locations is the same
* If the output is in the form of the simplest score, the Java
* At least l positions are the same, that is, l, l + 1, and L + 2 · m positions are the same.
* We consider the opposite. The total number is n ^ m. We calculate the probability that there is no number with the same position as l.
* If DP [I] [J] is set, the number of the first I is used to fill in the number of solutions for the J position (the number must be the same if no l position is set)
* DP [I] [J] = DP [I-1] [J] + sIgM (DP [I-1] [J-K] * C [M-(J-k)] [k]) k <= J & K <L
* In fact, it is to check the number of I. You can leave it empty and fill in a location where two locations are accumulated.
* The final answer is (N ^ m-DP [1 ~ N] [m])/(n ^ m)
*/

 

The main reason is that large numbers are troublesome. So I wrote it in Java. Let's practice Java!

 

 /*  * Zoj 3380 * Meaning: There are m positions. Fill in a number for each position. The value range is 1 ~ N: Ask if there are at least one probability with the same number of locations * the output is in the form of the simplest score. Therefore, Java with a large number * has at least one location, that is, l, L + 1, L + 2 · m positions are the same. * Considering the opposite, the total number is n ^ m. we calculate the probability that there are no numbers with the same positions as L. * Set DP [I] [J] to represent the number of front I, number of solutions for filling in J locations (the number must be the same if there are no l locations) * DP [I] [J] = DP [I-1] [J] + sIgM (DP [I-1] [J-K] * C [M-(J-k)] [k]) k <= J & K <L * is actually the number of I. You can leave it empty, enter a location, and add two locations. * The final answer is (N ^ m-DP [1 ~ N] [m])/(n ^ m)  */  Import Java. util .* ;  Import Java. Io .* ;  Import Java. Math .*;  Public   Class  Main {  Static Biginteger [] [] dp = New Biginteger [110] [110 ];  Static Biginteger [] [] C = New Biginteger [110] [110]; //  Combination number      Public   Static   Void Main (string Arg []) {Cin cin = New Partition ( New  Bufferedinputstream (system. In ));  For ( Int I = 0; I <105; I ++ ) {C [I] [ 0] = C [I] [I] = Biginteger. One;  For ( Int J = 1; j <I; j ++ ) C [I] [J] = C [I-1] [J-1]. Add (C [I-1] [J]);}  Int  N, 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) //  In this case, you can use the combination number to calculate the number.  {Biginteger ans = Biginteger. zero;  For ( Int I = 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 ( Int I = 0; I <= N; I ++ )  For ( Int J = 0; j <= m; j ++ ) {DP [I] [J] =Biginteger. Zero;} DP [ 0] [0] = Biginteger. One;  For ( Int I = 1; I <= N; I ++ )  For ( Int J = 1; j <= m; j ++ ){  For ( Int K = 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 ( Int I = 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 ));}}} 

 

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.