ZOJ 3380 Patchouli's Spell Cards(概率DP)
来源:互联网 发布:热敏打印机编辑软件 编辑:程序博客网 时间:2024/05/02 01:12
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3380
大致题意:m个元素,每个元素有n个阶段,元素有相同阶段就可以用一张魔法卡同时使用。问同时使用至少L个元素的概率。
分析:总的组合情况是n^m,至少有L个元素具有相同的阶段,那么就是L,L+1,L+2,……,m。
因为涉及到相同阶段元素个数的问题,不同的元素有联系,可能有DP相关,但是貌似直接写写不出来。主次关系换一下,计算不同阶段对应的元素的情况。dp[i][j]代表i个阶段j个元素的情况总数。有:
(对于一个新的阶段,情况有:在原来几个元素中存在,在一个新的元素中存在,在两个新元素存在,在三个新元素存在……在L-1个新元素存在,即K=0,k=1,k=2,……,k=L-1)
那么最后的结果应该就是 :
n,m,l 可以达到100,所以涉及到大数:
import java.math.BigInteger;import java.util.*;public class Main { static BigInteger [][]C=new BigInteger[105][105]; static BigInteger [][]dp=new BigInteger[105][105]; public static void init() { for(int i=0;i<105;i++){ for(int j=0;j<105;j++){ dp[i][j]=BigInteger.ZERO; } } } public static void main(String[] args){ for(int i=0;i<=100;i++){ C[i][0]=C[i][i]=BigInteger.ONE; for(int j=1;j<i;j++){ C[i][j]=C[i-1][j-1].add(C[i-1][j]); } } int m,n,L; Scanner cin = new Scanner(System.in); while(cin.hasNext()){ m=cin.nextInt(); n=cin.nextInt(); L=cin.nextInt(); init(); dp[0][0]=BigInteger.ONE; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int key=Math.min(L-1,j); for(int k=0;k<=key;k++){ dp[i][j]=dp[i][j].add(dp[i-1][j-k].multiply(C[m-(j-k)][k])); } } } BigInteger dpsum=BigInteger.ZERO; for(int i=0;i<=n;i++) { dpsum = dpsum.add(dp[i][m]); } BigInteger mu=BigInteger.valueOf(n).pow(m); BigInteger zi=mu.subtract(dpsum); BigInteger gd=mu.gcd(zi); mu=mu.divide(gd); zi=zi.divide(gd); if(zi.equals(BigInteger.ZERO)) System.out.println("mukyu~"); else System.out.println(zi+"/"+mu); } }}
0 0
- ZOJ 3380 Patchouli's Spell Cards (概率dp)
- ZOJ 3380 Patchouli's Spell Cards(概率DP)
- ZOJ-3380 Patchouli's Spell Cards(概率DP&&大数)
- ZOJ 3380 Patchouli's Spell Cards(概率DP)
- ZOJ 3380 Patchouli's Spell Cards 概率DP
- Zoj 3380 Patchouli's Spell Cards (概率dp)
- ZOJ 3380 Patchouli's Spell Cards( 概率DP)
- ZOJ 3380 Patchouli's Spell Cards 概率DP
- ZOJ 3380 Patchouli's Spell Cards [基础概率DP+大数]
- ZOJ 3380 Patchouli's Spell Cards(DP,大数)
- ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]
- ZOJ3380- Patchouli's Spell Cards(概率DP+计数)
- zoj3380 Patchouli's Spell Cards
- ★ZOJ 3380 Patchouli's Spell Cards 详细题解 (递推+组合数求方案数)
- BNU Cards 概率dp
- ZOJ--3822(概率dp)
- zoj 2852 Deck of Cards扑克牌(三维dp)
- ZOJ 3551 Bloodsucker (概率DP)
- web.xml中<load-on-startup></load-on-startup>中的作用
- 操作系统: 最佳适配算法和邻近适配算法的模拟实现(内存分配算法)
- ListView的上拉加载以及圆形图片的实现
- Android设计模式之一个例子让你彻底明白装饰者模式(Decorator Pattern)
- Codeforce Round #336--B. Hamming Distance Sum
- ZOJ 3380 Patchouli's Spell Cards(概率DP)
- for循环中i=0与i=arr.length容易被忽视的bug
- Objective-C与JavaScript的简易交互操作
- 从大数据的应用谈如何成为大数据大师的历程
- JAVA集合框架
- 数据结构课程设计-12月27日
- Mac 技巧
- 数据结构课程设计-宿舍管理系统
- FZOJ--2221-- RunningMan(水题)