方案数,$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); }
}
}
}

ZOJ 3380 Patchouli's Spell Cards的更多相关文章

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

    题意:1-n个位置中,每个位置填一个数,问至少有l个数是相同的概率. 可以转化求最多有l-1个数是相同的. dp[i][j]表示前i个位置填充j个位置的方案数,并且要满足上面的条件. 则: dp[i] ...

  2. 【ZOJ】3380 Patchouli's Spell Cards

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置填1~n的数,求至少有L个位置的数一样的概率(1 ...

  3. ZOJ-3380 Patchouli’s Spell Cards DP, 组合计数

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3380 题意:有m种不同的元素,每种元素都有n种不同的相位,现在假 ...

  4. 概率DP

    POJ 3744 Scout YYF I 这就是一个乱搞题,暴力发现TLE了,然后看了看discuss里说可以矩阵加速,想了一会才想明白怎么用矩阵,分着算的啊.先算f[num[i]-1]之类的,代码太 ...

  5. 概率dp专场

    专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 ...

  6. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  7. CF#335 Board Game

    Board Game time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input ...

  8. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  9. zoj 2734 Exchange Cards【dfs+剪枝】

    Exchange Cards Time Limit: 2 Seconds      Memory Limit: 65536 KB As a basketball fan, Mike is also f ...

随机推荐

  1. 不使用库函数、自己编写的(strlen、strcpy、strcmp、strcat、memcmp、memcpy、memmove)

    不使用库函数.自己编写的(strlen.strcpy.strcmp.strcat.memcmp.memcpy.memmove) //求字符串长度的函数 int my_strlen(const char ...

  2. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  3. 【题解】AHOI2009同类分布

    好开心呀~果然只有不看题解做出来的题目才会真正的有一种骄傲与满足吧ヾ(๑╹◡╹)ノ" 实际上这题只要顺藤摸瓜就可以了.首先按照数位dp的套路,有两维想必是省不掉:1.当前dp到到的位数:2. ...

  4. [洛谷P3203][HNOI2010]弹飞绵羊

    题目大意:有$n$个节点,第$i$个节点有一个弹力系数$k_i$,当到达第$i$个点时,会弹到第$i+k_i$个节点,若没有这个节点($i+k_i>n$)就会被弹飞.有两个操作: $x:$询问从 ...

  5. [Leetcode] word ladder 单词阶梯

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  6. mysql的对象

      mysql 常见的数据对象有哪些: DataBase/Schema Table Index View/Trigger/Function/Procedure   多Database用途: 业务的隔离 ...

  7. CentOS 6.4安装配置ldap

    CentOS 6.5安装配置ldap 时间:2015-07-14 00:54来源:blog.51cto.com 作者:"ly36843运维" 博客 举报 点击:274次 一.安装l ...

  8. 桥接物理网卡,pipwork指定ip,外网连接,研究salt+docker

    1.桥接物理网卡: 首先下载工具: yum -y install --enablerepo=epel bridge-utils 停止服务: 983 systemctl stop docker 删除do ...

  9. 拉格朗日乘数法 和 KTT条件

    预备知识 令 \(X\) 表示一个变量组(向量) \((x_1, x_2, \cdots, x_n)\) 考虑一个处处可导的函数 \(f(X)\), 为了方便描述, 这里以二元函数为例 对于微分, 考 ...

  10. [bzoj2124]等差子序列——线段树+字符串哈希

    题目大意 给一个1到N的排列\(A_i\),询问是否存在\(p_i\),\(i>=3\),使得\(A_{p_1}, A_{p_2}, ... ,A_{p_len}\)是一个等差序列. 题解 显然 ...