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~

跟:http://blog.csdn.net/qq_34374664/article/details/65935929对比理解下

 题目意思:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率
 输出要是最简分数的形式,所以用大数JAVA

大致思路:

首先如果考虑有L, L + 1, .... m个位置上是一样的方案数不好考虑, 但是可以从反面考虑, 计算只有1, 2, ... L - 1个位置有相同元素的方案数, 用总方案数n^m减去即可

如果用dp[i][j]表示用前i种元素填了j个位置(不一定是前j个), 且每个元素都没有使用达到L个, 的方案数的话有

dp[i][j] = sigma(dp[i - 1][j - k]*C[m - (j - k)][k]) (0 <= k <= min(m, l))

那么最后的答案就是 (n^m-dp[1~n][m])/(n^m)

即用前i个元素填充j个位置的方案数相当于前i - 1个元素填充了j - k个位置, 第i个元素要填充k个位置, 这k个位置可以来自于剩下的m - (j - k)个位置中的其中k个

那么不满足题意的方案总数是 sigma(dp[i][m]) (1 <= i <= n) 用所有可能的排列方案减去即可得到可行的方案数.

初始化dp[0][0] = 1, 其他值为0即可,这样有些不符合的情况自动变成0了

很明显只有当l > m时才会没有可能的方案

考虑到计算时数据很大, 使用java方便一些

讲道理 java真的是劲啊。。。

import java.math.BigInteger;
import java.util.BitSet;
import java.util.Scanner;public class Main
{static BigInteger[][] dp = new BigInteger[110][110];static BigInteger[][] c = new BigInteger[110][110];public static void main(String[] args){Scanner sc = new Scanner(System.in);for(int i = 0; i < 105; 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]);}int n, m, l;while(sc.hasNext()){m = sc.nextInt();n = sc.nextInt();l = sc.nextInt();BigInteger tot = BigInteger.valueOf(n).pow(m);if(l > m){System.out.println("mukyu~");continue;}
//          if(l>m/2)//这个时候可以直接用组合数求出来
//            {
//                BigInteger ans=BigInteger.ZERO;
//                for(int i=l;i<=m;i++)
//                    ans=ans.add(c[m][i].multiply(BigInteger.valueOf(n-1).pow(m-i)));
//                ans=ans.multiply(BigInteger.valueOf(n));
//                BigInteger gcd=ans.gcd(tot);
//                System.out.println(ans.divide(gcd)+"/"+tot.divide(gcd));
//                continue;
//            }for(int i = 0; i <= n; i++)for(int j = 0; j <= m; j++)dp[i][j] = BigInteger.valueOf(0);dp[0][0] = BigInteger.ONE;  //0个元素房0个位置的概率肯定是1 啊for(int i = 1; i <= n; i++)  //n个元素for(int j = 1; j <= m; j++)  //j个位置,不一定连续for(int k = 0; k < l && k <= j; k++) //代表第i个元素不放,房1个,放两个。。。最多放k个dp[i][j] = dp[i][j].add(dp[i-1][j-k].multiply(c[m-(j-k)][k]));
//          System.out.println(c[4][2]);BigInteger ans = BigInteger.ZERO;for(int i = 1; i <= n; i++)ans = ans.add(dp[i][m]);ans = tot.subtract(ans);BigInteger gcd = ans.gcd(tot);System.out.println(ans.divide(gcd)+"/"+tot.divide(gcd));}}
}

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

  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+大数]

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

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

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

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

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

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

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

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

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

  7. ZOJ 3380 Patchouli's Spell Cards

    方案数,$dp$. 总的方案数有$n^m$种,符合要求的直接算不好算,可以算反面,即不符合要求的. 设$dp[i][j]$表示前$i$种等级填了$j$个位置,那么$dp[i][j]=sum(dp[i- ...

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

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

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

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

最新文章

  1. java中countinue,.random(用于产生一个随机数)入门可看
  2. 爱国者强烈推荐:nanopiR1——你懂的功能,懂你的开发板
  3. C++静态多态与动态多态
  4. 什么是 CAS 机制
  5. python线上编辑问题_python django - static文件处理与线上部署测试
  6. Shell脚本-自动化部署反向代理、WEB、nfs
  7. Maven包装过程中跳过测试
  8. android 物联网 pdf,android复习资料(物联网141).pdf
  9. C#反射取得方法、属性、变量
  10. 一元(多元)线性回归分析之R语言实现
  11. Django 配置App特定类的富文本编辑器
  12. 锁卡,每插入一张新卡都需要进行解锁
  13. 关于职业规划最好最全面的一篇文章
  14. 沁园春·长沙 中法对照
  15. 传奇3单机服务器怎么修改器,自己是GM并架设了传奇3单机版,如何改变装备属性?...
  16. 计算机怎么改磁盘位置,如何修改磁盘0和磁盘1的硬盘位置
  17. 华为云确定性运维,为政务云平台稳定可靠运行保驾护航
  18. Launcher启动流程及初始化
  19. 简约响应式导航主题VIK WordPress模板
  20. 小米扫地机器人划区清扫定时_小米机器人怎么设定扫地区域 小米机器人设定扫地区域的方法...

热门文章

  1. 编程实用工具大全(前后端皆可用,不来瞅瞅?)
  2. 《加州之梦》 (California Dreaming)
  3. web网站服务器宕机应急,web服务器的宕机诊断方法
  4. 和AWS云游四海@姓“诸葛”,名“io”
  5. 【JTeam Champion NFT】NFT交易必备的四个工具
  6. CF#764(div.3A~D)dp进阶
  7. 树莓派4B 声音传感器DO模块
  8. 【推荐系统】协同过滤浅入(基于用户/项目/内容/混合方式)
  9. 关于redis多个哨兵sentinel在阿里云的坑 sdown sentinel或者failover-abort-not-elected
  10. SpringMVC整合Redis实战