程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ZOJ3380- Patchouli's Spell Cards(概率DP+計數)

ZOJ3380- Patchouli's Spell Cards(概率DP+計數)

編輯:C++入門知識

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 Devil 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 like Water Sign "Princess Undine", Moon Sign "Silent Selene" and Sun Sign "Royal Flare". In addition, she can combine the elements as well. So she can also cast high-level spell cards like Metal & Water Sign "Mercury Poison" and Fire, Water, Wood, Metal & Earth Sign "Philosopher's Stones" .

\ \

Assume that there are m different elements in total, each element has n different phase. Patchouli can use many 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 choZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc2UgPHZhcj5tPC92YXI+IGRpZmZlcmVudCBlbGVtZW50cywgZWFjaCBvZiB3aGljaCB3aWxsIGhhdmUgYSByYW5kb20gcGhhc2Ugd2l0aCB0aGUgc2FtZSBwcm9iYWJpbGl0eS4gV2hhdA=="s the probability that she can cast a spell card of which the level is no less than l, namely a spell card using at least l different 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 irreducible fraction. If it is impossible, output "mukyu~" instead.

Sample Input

7 6 5
7 7 7
7 8 9

Sample Output

187/15552
1/117649
mukyu~

題目意思:有m個元素,每個元素有n種相,現在從m個元素中,隨機抽取每一種元素的一種相,每種相取到的概率相同,相同的相可以融合,融合的個數就為它的度,問你最大的度大於等於L的概率。

做法 :
JAVA大數
dp[n][m] 表示的意思是 前n種相,用了m個元素,符合最大的度小於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 stub
		for(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 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved