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

题意:抽象的来说,就是给你M个不同的球,N种颜色,现在给球染色,问至少有L个球同一种颜色的概率。解法:总方案数很好算,为N^M,剩下的就是求至少L个球同色的方案数,其可以转换为 (总方案数-每种颜色至多L-1个球的方案数)。然后就是很明显的DP了,DP[I][J]表示已放完I种颜色,剩下J个球的方案数,那么转移方程为DP[I+1][J-K]+=DP[I][J]*C(J,K) 其中C()为组合数,K为当前颜色装的球数。

tip:  GCD(总方案数-每种颜色至多L-1个球的方案数,总方案数)==GCD(每种颜色至多L-1个球的方案数,总方案数)
import java.math.BigInteger;
import java.util.Scanner;public class Main {static BigInteger[][] dp = new BigInteger[105][105];static BigInteger[][] c = new BigInteger[105][105];static void init(){c[0][0] = BigInteger.valueOf(1);for(int i = 1; i <= 100; i++){c[i][0] = c[i][i]= BigInteger.valueOf(1);for(int j = 1; j < i; j++)c[i][j] = c[i-1][j-1].add(c[i-1][j]);}}static int min(int x, int y){return x < y ? x : y;}static void solve(int m, int n, int l){BigInteger fm = BigInteger.valueOf(n).pow(m);for(int i = 0; i <= n+1; i++)for(int j = 0; j <= m; j++)dp[i][j] = BigInteger.ZERO;dp[0][m] = BigInteger.ONE;for(int i = 1; i <= n; i++)for(int j = 0; j <= m; j++)for(int k = 0; k <= min(j,min(m,l-1)); k++)dp[i][j-k] = dp[i][j-k].add(dp[i-1][j].multiply(c[j][k]));BigInteger fz = dp[n][0];BigInteger gcd = fm.gcd(fz);fz = fm.subtract(fz).divide(gcd);fm = fm.divide(gcd);System.out.println(fz + "/" + fm);}public static void main(String[] args) {init();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~");elsesolve(m, n, l);}cin.close();}
}
												

ZOJ 3380 Patchouli's Spell Cards [基础概率DP+大数]相关推荐

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

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

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

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

  3. ZOJ-3380 Patchouli's Spell Cards(概率DP大数)

    Patchouli's Spell Cards http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 Time Limit:  ...

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

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

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

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

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

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

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

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

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

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

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

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

最新文章

  1. Rouche Theorem(Stein复分析)
  2. 腾讯绝地求生手游席卷全球,104个国家地区IOS登顶
  3. Verilog初级教程(7)Verilog模块例化以及悬空端口的处理
  4. .net框架、CLR和C#的版本之间的对应关系
  5. 在 Linux/UNIX 终端下使用 nload 实时监控网络流量和带宽使用
  6. C语言实用算法系列之二级指针用法简介
  7. SQL SERVER-Extendevent系统视图
  8. 开发接口文档_更优更稳更好,看文档驱动开发模式在AIMS中的优势
  9. python的字符编码叙述_Python: 熟悉又陌生的字符编码
  10. 使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容
  11. dudu: 图片显示错误问题,望更正
  12. javascript变量作用域一点总结
  13. 网上怎么下载ug软件ug怎样下载安装ug安装包免费领取
  14. 良心安利建筑行业3d打印模型素材网站
  15. 自从硬派网倒闭后,就没有什么好看的IT硬件网站了
  16. 关于利用Windows的Paint 3D制作透明背景图片的说明
  17. 一纬度横直线等于多公里_【地理】高中地理必修一知识点总结,考前必看
  18. linux系统下find删除目录下除一文件外的所有文件
  19. java htmlunit
  20. 个性化推荐系统,必须关注的五大研究热点

热门文章

  1. JavaScript创始人Brendan Eich访谈录
  2. Protege,SWRL和JESS的原理
  3. mysql中的判断是否有该条数据 如果有返回1 没有返回0
  4. Google Android开发入门与实战 视频教程 源代码 游戏应用开发 传送门
  5. SpringBoot-项目4-购物车(添加入购物车,购物车列表,购物车商品数量加减操作)
  6. ajax后台如何把对象转为json_Ajax向前后台传递json和转换
  7. 回顾维乐VELO创始人余彩云漫漫创新路
  8. AIMA:如何通过质量指标提高QA的绩效(译)
  9. 全新2009高校BBS上充满温馨的100个调情小笑话
  10. 联发科技嵌入式_【MTK联发科技嵌入式软件开发工程师面试题目|面试经验】-看准网...