方案数,$dp$。

总的方案数有$n^m$种,符合要求的直接算不好算,可以算反面,即不符合要求的。

设$dp[i][j]$表示前$i$种等级填了$j$个位置,那么$dp[i][j]=sum(dp[i-1][j-k]*c[m-(j-k)][k])$。初始化$dp[0][0]=1$。

符合要求的方案数为$n^m-dp[n][m]$。数字会爆$long$ $long$,上$java$。

import java.math.BigInteger;
import java.util.Scanner;public class Main {public static BigInteger GCD(BigInteger a,BigInteger b){if(b.equals(BigInteger.ZERO)) return a;return GCD(b,a.mod(b));}public static void main(String [] args){Scanner cin = new Scanner(System.in);int M,N,L;BigInteger c[][] = new BigInteger[105][105];BigInteger dp[][] = new BigInteger[105][105];for(int i=0;i<=100;i++)  c[i][0] = c[i][i] = BigInteger.ONE;for(int i=1;i<=100;i++){for(int j=1;j<i;j++){c[i][j]= c[i-1][j-1].add(c[i-1][j]);}for(int j=i+1;j<=100;j++) c[i][j] = BigInteger.ZERO;}while(cin.hasNext()){M=cin.nextInt();N=cin.nextInt();L=cin.nextInt();if(L>M) System.out.println("mukyu~");else {BigInteger n = BigInteger.valueOf(N);BigInteger fm = n.pow(M);BigInteger fz = new BigInteger("0");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<=L-1;k++){if(j-k<0) continue;if(M-(j-k)<0) continue;dp[i][j] = dp[i][j].add(dp[i-1][j-k].multiply(c[M-(j-k)][k]));}}}fz=dp[N][M]; fz = fm.subtract(fz);BigInteger gcd = GCD(fz,fm);fz=fz.divide(gcd); fm=fm.divide(gcd);System.out.println(fz+"/"+fm);}}}
}

转载于:https://www.cnblogs.com/zufezzt/p/6337372.html

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 详细题解 (递推+组合数求方案数)

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

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

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

  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(概率+大数)

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

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

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

  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,大数)

    转载请注明出处,谢谢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. android悬浮动态权限,android应用内悬浮窗-自动贴边,不需要权限!
  2. 超融合架构下的数据中心
  3. uva 11978 Fukushima Nuclear Blast (二分+多边形与圆交)
  4. Mock工具之Mockito实战
  5. sklearn自学指南(part55)--决策树
  6. COMET彗星(三)构建自己的COMET核心
  7. python顺序执行 toggle_pythonkivymd:如何使toggle_nav_drawer()函数工作?
  8. LTE学习:空口降低时延关键技术
  9. Redis教程:数据对象分析(一)
  10. 【基础】枚举学习笔记
  11. 摄影测量学——解析法相对定向
  12. Linux系统安装三菱编程软件,如何安装三菱plc编程软件gx developer
  13. 小甲鱼c语言照片,【跟着小甲鱼学C语言】P14 给大家介绍对象
  14. springboot校园二手交易平台的设计与实现毕业设计源码260839
  15. 网站漏洞扫描工具AWVS_v13下载和安装
  16. MSP430单片机个人学习笔记
  17. XUL透明异形旋转窗体
  18. W25Q128FV译文(一)
  19. CURD同事狂刷阿里面试指南(恒山版),直接斩获七个offer
  20. android输入法中文在哪里设置,android输入法怎么设置中文

热门文章

  1. deepfakes怎么用_手把手教你使用 Deepfakes 换脸
  2. 使用Template控制Editor显示方式
  3. 液晶屏背光板的分类及知识点
  4. hdu 1824-Let's go home 2-SAT (模板)
  5. android+酷炫动画效果,Android简单酷炫点击动画(附源码)
  6. Android摄像头 只拍摄SurfaceView预览界面特定区域内容(矩形框)---完整实现(原理 底层Surface
  7. 无源晶振(crystal)和有源晶振(oscillator)的区别
  8. java淘金者_Java游戏淘金者源码JAVA游戏源码下载
  9. 谈我所经历的区块链历程
  10. HDU 1718 Rank counting sort解法