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~
There are m elements, and each element has n phases. Now, from M elements, a phase of each element is randomly selected, and the probability of each element is the same, if the same number of elements can be merged, the number of fusion values is the degree of convergence. the maximum degree is the probability that the number is greater than or equal to L.
Practice:
Java large number
DP [N] [m] indicates the first n phases. m elements are used to match the number of solutions with the maximum degree less than l.
dp[n][m] = sum(dp[n-1][m-k]*count[M-(m-k)][k])
import java.util.*;import java.math.*;public class Main {static int maxn = 110;public static BigInteger[][] dp =new BigInteger[110][110];public static BigInteger[][] count = new BigInteger[110][110];public static void main(String[] args) {// TODO Auto-generated method stubfor(int i = 0; i < maxn; i++){count[i][0] = BigInteger.ONE;count[i][i] = BigInteger.ONE;for(int j = 1; j < i; j++){count[i][j] = count[i-1][j].add(count[i-1][j-1]);}}Scanner scan = new Scanner(System.in);while(scan.hasNextInt()){int m = scan.nextInt();int n = scan.nextInt();int l = scan.nextInt();BigInteger nn = BigInteger.valueOf(n).subtract(BigInteger.ONE);BigInteger fm = BigInteger.valueOf(n).pow(m),fz = BigInteger.ZERO;if(l > m){System.out.println("mukyu~");}else{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 = 0; j <= m; j++){for(int k = 0; k <= j&& k <l; k++){dp[i][j] = dp[i][j].add(dp[i-1][j-k].multiply(count[m-(j-k)][k])); }}}fz = fm.subtract(dp[n][m]);BigInteger gcd = fz.gcd(fm);fz = fz.divide(gcd);fm = fm.divide(gcd);System.out.println(fz+"/"+fm);}}scan.close();}}