ZOJ3380- Patchouli's Spell Cards(概率DP+计数)

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 choose m different 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 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 <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();
	}

}

ZOJ3380- Patchouli's Spell Cards(概率DP+计数),布布扣,bubuko.com

ZOJ3380- Patchouli's Spell Cards(概率DP+计数)

时间: 2024-10-05 07:11:23

ZOJ3380- Patchouli's Spell Cards(概率DP+计数)的相关文章

Zoj 3380 Patchouli&#39;s Spell Cards (概率dp)

题目大意: 用(1 2 3 ... n) n个数填充 m个位置,问最少相同的数字出现的数量不少于I 的概率 思路分析: 逆向思考,求铺满最多的数量不够I 个的方案数. 每次用一个数字去铺,铺M个位置,每个数字最多铺 不够I个. dp[i][j]表示枚举到了第i个数字,前i个数字铺了j个位置的方案数. 考虑到组合计数 用Java import java.util.*; import java.io.BufferedInputStream; import java.math.*; public cl

【概率DP】 ZOJ 3380 Patchouli&#39;s Spell Cards

通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率 * 设 dp[i][j]表示用前i个数,填充j个位置的方案数(要符合没有L个位置是一样的数) * dp[i][j]=dp[i-1][j]+Sigm( dp[i-1][j-k]*C[m-(j-k)][k] ) k<=j&&k<L * 其实就是看第i个数,可以不填,填一个位置,两个位置······这样累加过来. * 那么最后的答案就是

【ZOJ】3380 Patchouli&#39;s Spell Cards

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置填1~n的数,求至少有L个位置的数一样的概率(1<=n,m,l<=100) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct inum { static const int N=205,

UVALive 6672 Bonus Cards 概率dp

题意呢 就是有两种售票方式 一种是icpc 一种是其他方式 icpc抢票成功的概率是其他方式的2倍…… 这时 一个人出现了 他通过内幕知道了两种抢票方式各有多少人 他想知道自己如果用icpc抢票成功的概率是多少 用acm抢票成功的概率是多少…… 做过不多的概率dp 还在摸索…… dp[i][j]代表第i轮有j个icpc的人已经有票了…… 当然同时i-j个通过其他方式抢票的人也有票了 这就是用同样的函数搜两次的原理…… 优化一次i<=a 一次是把初始化放到for里…… 第一次见这么卡时间的题……

LightOJ1364---Expected Cards(概率dp+三进制状压)

Taha has got a standard deck of cards with him. In addition to the 52 regular ones, there are 2 joker cards. Every regular card has a rank and a suit. The ranks in ascending order are: A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q and K. The suit of a card can

概率DP入门题

一 概率问题的论文 1.算法合集之<信息学竞赛中概率问题求解初探> 2.有关概率和期望问题的研究 3.算法合集之<浅析竞赛中一类数学期望问题的解决方法> 二 入门题目 1.POJ 3744 Scout YYF I (简单题) 题意:一条路上有n个地雷 ,a[i]代表第i个地雷放的位置,求安全走过这段路的概率 分析:若第k个位置有地雷则安全走过这个位置的方案为在第k-1个位置跳两步概率为(1-p) 从反面考虑 已经安全走过了第i-1个雷 则在第i个雷的死掉的概率为 1-p(从走到a[

HDU4336-Card Collector(概率DP求期望)

Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2195    Accepted Submission(s): 1034 Special Judge Problem Description In your childhood, do you crazy for collecting the beautifu

HDU 4336——Card Collector——————【概率dp】

Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3407    Accepted Submission(s): 1665Special Judge Problem Description In your childhood, do you crazy for collecting the beautiful

poj 2537 Tight words 概率dp

分析: 用计数dp思想:DP[I][J]=(DP[I-1][J-1]+DP[I-1][J]+DP[I-1][J+1]),最后再除pow(k+1,n)容易爆精度,改用概率dp思想DP[I][J]=(DP[I-1][J-1]+DP[I-1][J]+DP[I-1][J+1])/(k+1)即可. 代码: //poj 2537 //sep9 #include<iostream> using namespace std; double dp[128][16]; int main() { int k,n;