Description

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.


题意:

抽象的来说,就是给你M个不同的球,N种颜色,现在给球染色,问至少有L个球同一种颜色的概率。


范围:

N,M,L<=100

解法:

总方案数很好算,为N^M,剩下的就是求至少L个球同色的方案数,其可以转换为 (总方案数-每种颜色至多L-1个球的方案数)。

然后就是很明显的DP了,DP[I][J]表示已放完I种颜色,剩下J个球的方案数,那么转移方程为

DP[I+1][J-K]+=DP[I][J]*C(J,K) 其中C()为组合数,K为当前颜色装的球数。

注意会暴longlong,需要用大数,我这里使用了JAVA写大数

import java.math.BigInteger;
import java.util.Scanner;
public class Main{static BigInteger[][] dp = new BigInteger[111][111];static BigInteger[][] c = new BigInteger[111][111];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=0;i<n;i++){for(int j=0;j<=m;j++){for(int k=0;k<=min(j,min(m,l-1));k++){dp[i+1][j-k]=dp[i+1][j-k].add(dp[i][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();int m,n,l;Scanner sc = new Scanner(System.in);while(sc.hasNext()){m=sc.nextInt();n=sc.nextInt();l=sc.nextInt();if(l>m)System.out.println("mukyu~");else solve(m,n,l);}sc.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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

最新文章

  1. 小规模网络数据公开数据_大规模的在线公开课程曾经是100%免费的。 但是他们没有那样做。...
  2. 从0学习css开发之 font-size的基本用法
  3. C#里的一些加密解密标准函数示例——DES,SHA1,RSA
  4. 如何给Docker hub用户上传头像
  5. 面向Java程序员的20大Spring REST面试问题答案
  6. android 简单实现圆角,Android 实现圆角图片的简单实例
  7. 磁盘阵列服务器Intel C610系列,超微6048R-E1CR36N 36盘位存储服务器 磁盘阵列
  8. 为jquery.AutoComplete添加触发事件
  9. Java中无法到达的语句
  10. 阶段3 3.SpringMVC·_03.SpringMVC常用注解_6 CookieValue注解
  11. MyEclipse安装配置maven插件
  12. python计算器界面设计_Python 计算器界面设计
  13. md文件 markdown打开工具(typora)
  14. ISO9001、ISO14001和ISO45001体系审核时需要准备哪些资料?
  15. 非线性光学近似计算机应用,浅谈非线性光学的发展及应用
  16. IcedTea6 1.7.6、1.8.3和1.9.2补丁程序信息泄漏
  17. Word编号设置和跳到尾页快捷键
  18. 【FPGA——工具篇】:Modelsim SE-64 10.4下载、破解、安装过程
  19. 观点 | ​苏宁传统零售业“数字化转型”经验分享
  20. python-flask(二)集成bootstrap、集成web表单、集成邮件发送

热门文章

  1. [小代码]通过IP和端口连接到远程摄像机
  2. 小歆记账 php,小歆记账WebApp项目(Web服务端)
  3. MES精益制造管理系统八大功能
  4. vue父子组件之间的传值,及互相调用父子组件之间的方法
  5. LAXCUS分布式操作系统6.0 RP1版本正式发布
  6. 会声会影最新版:会声会影2021中文版它来啦!
  7. 会声会影 我们后惠无期
  8. 聪明点 比较购物网站SEO分析
  9. Apache shiro 漏洞总结
  10. 新加坡金融科技节之声|蚂蚁金服CTO程立:面向全球开放能力