ZOJ 3380 Patchouli's Spell Cards [基础DP+大数]
2015-12-01 20:31
363 查看
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" .
![](http://7xjob4.com1.z0.glb.clouddn.com/f524129ed1ec9593a9ed30dc59be7124)
![](http://7xjob4.com1.z0.glb.clouddn.com/61c1687c279f9f152405f36e0e99c558)
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写大数
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 [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(); } }
相关文章推荐
- Accurate Scale Estimation for Robust Visual Tracking(DSST) 学习总结
- sys.dm_os_waiting_tasks 引发的疑问(上)
- Bootstrap框架分分钟解决响应式导航(直接上代码)
- Tomcat+Solr构建企业级搜索引擎
- Add Digits
- 疯狂Java程序员16堂课---第6课流程控制的陷阱读书笔记:
- writeLog
- 蓝桥杯OJ刷题日记——13-基础练习 数列排序
- iOS 七层网络协议
- QP之QK原理
- windows8建立局域网的方法
- 从全景推出微图网看IP时代下图片价值的激增
- linux图形界面编程基本知识(X11, xorg, gdm/gnome)
- C++精度控制
- iOS 9 适配系列教程
- 利用caffe中自带的工具来可视化loss 和accuracy
- 【C#】按钮长按
- nyoj--38--布线问题(克鲁斯卡尔)
- HTML5----大牛对HTML5的思考总结(一)(笔记篇)
- C++终极复习篇(二)----认知C++