方案数,$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. 有用的Java注解

    好处: 能够读懂别人的代码,特别是框架相关的代码: 让编程更加简洁,代码更加清晰. 使用自定义注解解决问题!! Java1.5版本引入. Java中的常见注解 @Override:告诉使用者及编译器, ...

  2. Problem Collection I 位运算

    XOR ARC 092B CF 959E xor-MST CF 959F

  3. LwIP - raw/callback API、协议栈API(sequential API)、BSD API(或者说 SOCKET API)

    1.使用raw/callback API编程,用户编程的方法是向内核注册各种自定义的回调函数,回调函数是与内核实现交换的唯一方式. recv_udp, accept_function, sent_tc ...

  4. HTML5之SVG详解(一):基本概括

    转载自:http://www.cnblogs.com/hupeng/archive/2012/12/21/2828456.html 1.背景 SVG是Scalable Vector Graphics的 ...

  5. 转:Linux 目录结构和常用命令

    转自:http://www.cnblogs.com/JCSU/articles/2770249.html仅为学习参考之用 一.Linux目录结构 你想知道为什么某些程序位于/bin下,或者/sbin, ...

  6. 着色方案(bzoj 1079)

    Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木 ...

  7. RPC-Thrift(三)

    TProtocol TProtocol定义了消息怎么进行序列化和反序列化的. TProtocol的类结构图如下: TBinaryProtocol:二进制编码格式: TCompactProtocol:高 ...

  8. 汕头市队赛 yyl杯1 T1

    A SRM 05 - YYL 杯 R1 背景 傻逼题 描述 给一个序列,序列里只有两种元素1和2.现在要从序列里选出一些非空子序列使得子序列里两种元素数量相同.问有多少种方案数? 输入格式 多组数据 ...

  9. vue入门介绍

    vue:解决前端大型应用的开发,将之前几十个.几百个.更多的HTML页面集成1个html页面(单页面应用)jquery:前端方法库bootstrap:UI组件库 angular/react这两个框架都 ...

  10. Oracle 脚本记录

    给表创建序列或触发器 create or replace procedure p_createseq(tablename in varchar2,key in varchar2) Authid Cur ...