Patchouli's Spell Cards

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957

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 ≤ mnl ≤ 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~

References

题目大意:有m种不同的元素,每个元素有n种不同的阶段,只有处于相同阶段的元素才能放入咒语中,求一个咒语中至少有l种不同的元素的概率?

题目大概直译就是这样,但是完全没有思路

看了题解后发现大神总结抽象能力好强,抽象成:有m个位置,在每个位置随机填上1~n个数,求相同的数至少有l的概率?

即使这样还是没有思路,认为是容斥什么的直接计算,完全想不到概率DP

大致思路如下:正难则反,统计填满数后相同的数小于l的情况

设dp[i][j]表示前i个数占据j个位置的方案数(且每个数占据的位置小于l)

该状态可由前i-1个数占据max(j-l+1,0) ~ j个位置转移而来,保证第i个数占据的位置数小于l

则状态转移方程为:dp[i][j]=∑dp[i-1][j-k]*c(m-j+k,k) (k<=j&&k<l)

则∑dp[i][m] 表示用i个数填满后,每个数出现次数都小于ll时的方案数

则n^m-∑dp[i][m] 为相同的数至少有l的的方案数

import java.util.*;
import java.math.*;public class Main {static BigInteger[][] dp=new BigInteger[105][105];static BigInteger[][] c=new BigInteger[105][105];static BigInteger fact,deno,gcd;public static void main(String[] argv) {for(int i=0;i<=100;++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]);//杨辉三角形计算组合数}}Scanner cin=new Scanner(System.in);int m,n,l;while(cin.hasNext()) {m=cin.nextInt();n=cin.nextInt();l=cin.nextInt();if(l>m) {System.out.println("mukyu~");}else if(l>m/2) {//如果至少需要的阶段相同的元素超过一半,则必定只有一种相同的阶段fact=BigInteger.ZERO;deno=BigInteger.valueOf(n).pow(m);//合法的总方案数for(int i=l;i<=m;++i) {//枚举阶段相同的元素个数fact=fact.add(c[m][i].multiply(BigInteger.valueOf(n-1).pow(m-i)));//从m个元素中选择i个元素其阶段相同,其余m-i个元素可在剩下的n-1个阶段任选}fact=fact.multiply(BigInteger.valueOf(n));//不同元素的相同阶段共有n种gcd=fact.gcd(deno);//分子分母的最大公约数System.out.println(fact.divide(gcd)+"/"+deno.divide(gcd));//输出最简分数}else {//存在多种相同的阶段的元素个数都超过l时,进行DPfor(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]));}}}fact=BigInteger.ZERO;deno=BigInteger.valueOf(n).pow(m);//合法的总方案数for(int i=1;i<=n;++i) {fact=fact.add(dp[i][m]);}fact=deno.subtract(fact);gcd=fact.gcd(deno);//分子分母的最大公约数System.out.println(fact.divide(gcd)+"/"+deno.divide(gcd));//输出最简分数}}}
}

ZOJ-3380 Patchouli's Spell Cards(概率DP大数)相关推荐

  1. ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]

    Description Patchouli Knowledge, the unmoving great library, is a magician who has settled down in t ...

  2. ZOJ 3380 Patchouli's Spell Cards( 概率DP)

    题意:用n个数填充m个位置,问有大于等于l个相同数字的概率. 这个题看了很多题解,大部分代码都是有点问题的,一开始dp的状态都是一样的.(具体见下) 思路:设dp[i][j] 为用前i个数填充j个位置 ...

  3. ZOJ 3380 Patchouli's Spell Cards 概率DP

    题意:给你m个位置,每个位置放一个数,区间为1-n,问你至少有L个位置是一样的数的概率,结果用分数表示 思路:这题我们从反向入手,dp[i][j]代表前i个数,放到j个位置,且没有L个或以上的位置有相 ...

  4. ZOJ 3380 Patchouli's Spell Cards(DP,大数)

    转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:有m个位置,每个位置填入一 ...

  5. ZOJ 3380 Patchouli's Spell Cards(概率+大数)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置可以放n种数字(1-n).问至少有L个 ...

  6. ZOJ 3380 Patchouli's Spell Cards(概率DP)

    Patchouli's Spell Cards Time Limit: 7 Seconds      Memory Limit: 65536 KB Patchouli Knowledge, the u ...

  7. ZOJ 3380 Patchouli's Spell Cards [基础概率DP+大数]

    Patchouli's Spell Cards Time Limit: 7 Seconds      Memory Limit: 65536 KB Patchouli Knowledge, the u ...

  8. ★ZOJ 3380 Patchouli's Spell Cards 详细题解 (递推+组合数求方案数)

    Patchouli's Spell Cards Time Limit: 7 Seconds      Memory Limit: 65536 KB Patchouli Knowledge, the u ...

  9. 【概率DP】 ZOJ 3380 Patchouli's Spell Cards

    通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率* 设 dp[i][j]表示用前i个数,填充j个位置 ...

  10. ZOJ 3380 Patchouli's Spell Cards——组合数+概率dp

    题意: m个位置,每个位置可以等概率填n种数,规定一个数字出现次数不能超过L次(注意不是连续L次),填完m个位置后满足约束的概率是多少. 思路: 定义dp[i][j]为前i种数字填充j个位置(j个位置 ...

最新文章

  1. Go如何使用session
  2. 如何解决Error: failed PB timebomb check
  3. jQuery html表格排序插件:tablesorter
  4. matlab中平方根法,平方根法和改进的平方根法解线性方程组(Matlab程序)
  5. Java调用百度API实现翻译
  6. stm8s103k3 周期 捕获_STM8S 输入捕获学习
  7. java入门学习(三:数据类型)
  8. 文化网,武汉文化网,湖北文化网——炎黄文化常识
  9. PACS—医学影像信息化的基础
  10. 离职员工住房公积金提取办法(深圳)
  11. 业务数据分析-常见业务指标
  12. 2021邓州市二高高考成绩查询,邓州市二高中举行2021届高三冲刺高考誓师大会暨毕业典礼...
  13. form表单下的button不设置type会自动提交表单
  14. 一文彻底弄懂工厂模式(Factory)
  15. 自己制作Chrome绿色版本。
  16. Exchange控制台错误:WinRM客户端已将请求发送到HTTP服务器
  17. ISM330DHCXTR IMU-惯性测量单元 工业物联网 运动传感器
  18. qsort 用法详解
  19. 让ie浏览器下载word,excel,而不是直接打开
  20. 在物联网(IOT)背景下服务器怎样和电控板打交道的?

热门文章

  1. source insight无法识别函数定义
  2. VC驿站《VC++实战HTTP之POST》教程
  3. 【机器人栅格地图】基于蚁群优化遗传算法求解机器人栅格地图最短路径规划问题附Matlab源码
  4. 天空之城 10孔口琴
  5. 我的世界天空之城服务器位置,我的世界1.7.2服务器天空之城
  6. 千里马Android Framework-Binder通信总结流程图
  7. 40多个JAVA手机游戏打包
  8. 液晶面板价格高涨,OLED电视或迎来春天
  9. 2020FME博客大赛——地下管线-雨水管网 三维可视化
  10. python在线diff工具在哪_Python - deepdiff