zoj3380 Patchouli's Spell Cards
来源:互联网 发布:淘宝退货被拒绝怎么办 编辑:程序博客网 时间:2024/05/20 18:42
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" andSun Sign "Royal Flare". In addition, she can combine the elements as well. So she can also cast high-level spell cards likeMetal & 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 hasn 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 thanl, namely a spell card using at least l different elements.
Input
There are multiple cases. Each case contains three integers 1 ≤ m, n, l ≤ 100. Process to the end of file.
Output
For each case, output the probability as irreducible fraction. If it is impossible, output "mukyu~" instead.
Sample Input
7 6 57 7 77 8 9
Sample Output
187/155521/117649mukyu~
当l>m明显无解,l>m/2,可直接用组合数求出,当l<=m/2,这里就不能用组合数求了,因为,这里会有重复,用dp[i][j]表示前i个数字,第j位,满足某个数字小于l的个数,那么我们可以得出dp[i][j]=dp[i][j-k]c[m-j+k][k],也就是第i个数字,可以放1-k个位置,这样就可以得出答案了!
import java.math.BigInteger;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner a=new Scanner(System.in);int M=150;BigInteger dp[][]=new BigInteger[150][150];BigInteger an[][]=new BigInteger[150][150];BigInteger one ,zero;one=BigInteger.ONE;zero=BigInteger.ZERO;for(int i=0;i<120;i++){dp[i][i]=dp[i][0]=dp[0][i]=one;for(int j=1;j<i;j++){dp[i][j]=dp[i-1][j-1].add(dp[i-1][j]);}}while(a.hasNext()){int m,n,l;BigInteger ans,nn,mm,ll,all,gcd;m=a.nextInt();n=a.nextInt();l=a.nextInt();nn=BigInteger.valueOf(n);mm=BigInteger.valueOf(m);ll=BigInteger.valueOf(l);ans=nn.pow(m);if(l>m){System.out.print("mukyu~\n");continue;}if(l>m/2){all=zero;for(int i=l;i<=m;i++){all=all.add(dp[m][i].multiply(BigInteger.valueOf(n-1).pow(m-i)));}all=BigInteger.valueOf(n).multiply(all);gcd=ans.gcd(all);System.out.println(all.divide(gcd)+"/"+ans.divide(gcd));continue;}for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)an[i][j]=zero;an[0][0]=one;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){for(int k=0;k<=j&&k<l;k++){an[i][j]=an[i][j].add(an[i-1][j-k].multiply(dp[m-j+k][k]));}}all=zero;for(int i=1;i<=n;i++){all=all.add(an[i][m]);}all=ans.subtract(all);gcd=ans.gcd(all);System.out.println(all.divide(gcd)+"/"+ans.divide(gcd));}}}
- zoj3380 Patchouli's Spell Cards
- ZOJ3380- 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+大数]
- ZOJ 3380 Patchouli's Spell Cards(概率DP)
- ★ZOJ 3380 Patchouli's Spell Cards 详细题解 (递推+组合数求方案数)
- [1119] Patchouli's Books
- Cards
- Cards
- Cards
- 月光博客6月12日翻译了《写给新手程序员的一封信》
- eclipse 插件安装
- 第九周 给年份和月份,判断该月有多少天
- ZOJ 3365 Integer Numbers 思路题
- Objective-C如何使用对象集合之学习系列三
- zoj3380 Patchouli's Spell Cards
- csdn俱乐部第八周会议
- sssss
- Kaitou Kid - The Phantom Thief (1) 第三次周赛
- Different ways to specify libraries to gcc/g++
- cocos2d-x ——菜单层(CCMenuItemSprite)三
- 大话数据结构十二:字符串的模式匹配(BM算法)
- shell中的引号,单引号,反引号
- 【转】 由 serverAdd.sin_addr.s_addr 引发的思考