题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957

题意:m个位置,每个位置可以放n种数字(1-n)。问至少有L个位置数字一样的概率?

思路:反着想,我们先求出没有L个位置数字一样的放法ans。dp[i][j]表示前i种数字占据j个位置的放法数,dp[i][j]=sum(dp[i-1][j-k]*C[m-(j-k)][k])(k<L)。则ans=sum(dp[i][m])。则真正的答案Ans=n^m-ans。

import java.util.*;
import java.math.*;public class Main{static BigInteger dp[][]=new BigInteger[105][105];static BigInteger C[][]=new BigInteger[105][105];public static void puts(String s){System.out.println(s);}public static void main(String[] args){int i,j,k;BigInteger one=BigInteger.ONE,zero=BigInteger.ZERO;for(i=0;i<=100;i++){C[i][0]=C[i][i]=one;for(j=1;j<i;j++) C[i][j]=C[i-1][j-1].add(C[i-1][j]);}int n,m,L;Scanner S=new Scanner(System.in);while(S.hasNext()){m=S.nextInt();n=S.nextInt();L=S.nextInt();if(L>m){puts("mukyu~");continue;}for(i=0;i<=n;i++) for(j=0;j<=m;j++) dp[i][j]=zero;dp[0][0]=one;for(i=1;i<=n;i++) for(j=1;j<=m;j++) for(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]));}BigInteger ans=zero;for(i=1;i<=n;i++) ans=ans.add(dp[i][m]);BigInteger tot=BigInteger.valueOf(n).pow(m);ans=tot.subtract(ans);BigInteger gcd=ans.gcd(tot);ans=ans.divide(gcd);tot=tot.divide(gcd);System.out.println(ans+"/"+tot);}}
}

  

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

最新文章

  1. Leangoo项目管理软件管理 传统硬件产品开发全流程
  2. c++局域网主动ftp_如何在局域网中实现 ARP 攻击
  3. Srinath总结 架构师们遵循的 30 条设计原则
  4. SQL Server默认1433端口修改方法
  5. aix oracle监听配置_Oracle数据库03用户权限与数据库的连接
  6. osm数据导入mysql_OSM(OpenStreetMap) poi、路网 数据导入 PostgreSQL
  7. 【回顾】推荐系统工程师技能树
  8. java map 容器_java容器-map的常用实现及原理
  9. win7看不到共享打印机的计算机,win7搜不到共享打印机怎么办?-解决win7找不到共享打印机的方法 - 河东软件园...
  10. pandas excel合并去重
  11. Android前台服务讲解一
  12. 【PyTorch】pkg_resources
  13. 脱光解决方案——一枚大佬一枚白骨精
  14. 湘潭大学数据库考试(郭云飞)
  15. excel后几位数字自动变成000
  16. 修11代12代希捷坏道
  17. 计算机辅助翻译在翻译中的应用,计算机辅助翻译系统在翻译教学中的应用
  18. 从「降维打击」谈「降维」
  19. 【cartographer_ros】一 : ros系统下的快速安装
  20. python strip()方法使用

热门文章

  1. MySQL 索引背后的数据结构及算法原理
  2. Delphi XE2 之 FireMonkey 入门(41) - 控件基础: TListBox
  3. Blend 动画 模板
  4. Java后端避坑——如何使用注解忽略掉JavaBean的属性值
  5. 地铁19号线首段盾构区间双线贯通
  6. redis安全设置及主从配置
  7. 一张图之——JSDuck
  8. mysql中联合查询
  9. Git tag常用命令分享
  10. 商务口语:议价时可能用到的句子