【BZOJ 1004】【HNOI 2008】Cards
http://www.lydsy.com/JudgeOnline/problem.php?id=1004
注意数据给出的m是一个没有单位元的置换群!
用Burnside引理,然后对每个置换群dp一下就可以了。
#include<cstdio>
#include<bitset>
#include<cstring>
#include<algorithm>
using namespace std;
int a[63], Sr, Sb, Sg, m, p, n, ans = 0;
int ipow(int w, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = ret * w % p;
w = w * w % p;
b >>= 1;
}
return ret;
}
int f[63][63][63][63], w[63], tot;
bitset <64> vis;
int dp() {
vis.reset(); tot = 0;
for (int i = 1; i <= n; ++i)
if (!vis[i]) {
vis[i] = 1;
w[++tot] = 1;
int tmp = a[i];
while (!vis[tmp]) {
vis[tmp] = 1;
++w[tot];
tmp = a[tmp];
}
}
for (int i = 1; i <= tot; ++i)
for (int R = 0; R <= Sr; ++R)
for (int B = 0; B <= Sb; ++B)
for (int G = 0; G <= Sg; ++G) {
f[i][R][B][G] = 0;
if (R >= w[i]) (f[i][R][B][G] += f[i - 1][R - w[i]][B][G]) %= p;
if (B >= w[i]) (f[i][R][B][G] += f[i - 1][R][B - w[i]][G]) %= p;
if (G >= w[i]) (f[i][R][B][G] += f[i - 1][R][B][G - w[i]]) %= p;
}
return f[tot][Sr][Sb][Sg];
}
int main() {
scanf("%d%d%d%d%d", &Sr, &Sb, &Sg, &m, &p);
n = Sr + Sb + Sg; f[0][0][0][0] = 1;
for (int j = 1; j <= n; ++j) a[j] = j;
(ans += dp()) %= p;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) scanf("%d", a + j);
(ans += dp()) %= p;
}
printf("%d\n", ans * ipow(m + 1, p - 2) % p);
return 0;
}
【BZOJ 1004】【HNOI 2008】Cards的更多相关文章
- 【BZOJ 1005】【HNOI 2008】明明的烦恼
http://www.lydsy.com/JudgeOnline/problem.php?id=1005 答案是\[\frac{(n-2)!}{(n-2-sum)!×\prod_{i=1}^{cnt} ...
- 【BZOJ 1043】【HNOI 2008】下落的圆盘 判断圆相交+线段覆盖
计算几何真的好暴力啊. #include<cmath> #include<cstdio> #include<cstring> #include<algorit ...
- 【BZOJ 1007】【HNOI 2008】水平可见直线 解析几何
之前机房没网就做的这道题,用的解析几何判断交点横坐标 #include<cmath> #include<cstdio> #include<cstring> #inc ...
- 【BZOJ 1004】 1004: [HNOI2008]Cards (置换、burnside引理)
1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有多少种染色方案,Sun很 ...
- 【BZOJ 1004】 [HNOI2008]Cards
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 [题意] 给你sr+sb+sg张牌,(令n=sr+sb+sg),让你把这n张牌染 ...
- 【HNOI 2008】 越狱
[题目链接] 点击打开链接 [算法] 显然,越狱情况数 = 总情况数 - 不能越狱的情况数 很容易发现,总情况数 = M^N 不能越狱的情况数怎么求呢? 我们发现,不能越狱的情况,其实就是第一个人任选 ...
- 【BZOJ】【1004】【HNOI2008】Cards
Burnside/Polya+背包DP 这道题目是等价类计数裸题吧……>_> 题解:http://m.blog.csdn.net/blog/njlcazl_11109/8316340 啊其 ...
- [BZOJ 1004] [HNOI2008] Cards 【Burnside引理 + DP】
题目链接:BZOJ - 1004 题目分析 首先,几个定义和定理引理: 群:G是一个集合,*是定义在这个集合上的一个运算. 如果满足以下性质,那么(G, *)是一个群. 1)封闭性,对于任意 a, b ...
- 【BZOJ】3052: [wc2013]糖果公园
http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]} ...
随机推荐
- 【vijos】P1083 小白逛公园
[算法]线段树 [题解] 学自:https://vijos.org/p/1083/solution(wang_yanheng的回答) 回溯时维护一段区间的以下域: sumL:从左端点起连续区间的最大和 ...
- Spring的使用优点
spring事物配置,声明式事务管理和基于@Transactional注解的使用 spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务管理使用TransactionTemplate或者 ...
- HDU 1599 find the mincost route (最短路 floyd)
题目链接 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....V ...
- bzoj 2434 fail tree+dfs序
首先比较明显的是我们可以将字符串组建立ac自动机,那么对于询问s1字符串在s2字符串中出现的次数,就是在以s1结尾为根的fail tree中,子树有多少个节点是s2的节点,这样我们处理fail tre ...
- 【Linux学习】nohup后台运行程序以及输出重定向
Linux有两种命令使程序后台运行 第一种:支持后台运行,但是关闭终端的话,程序也会停止 command & 第二种:支持后台运行,关闭终端后,程序也会继续运行 nohup command & ...
- python模块 zipfile
zipfile是python里用来做zip格式编码的压缩和解压缩的,由于是很常见的zip格式,所以这个模块使用频率也是比较高的zipfile里有两个非常重要的class, 分别是ZipFile和Zip ...
- 配置连接的IP、端口、以及相应的数据库
解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. //使用autoload加载相关库,这边重点就是为了requir ...
- [Linux]Linux printf 输出重定向【转】
转自:http://www.cnblogs.com/aaronLinux/p/6765145.html?utm_source=itdadao&utm_medium=referral 方法一 # ...
- JavaScript中数组对象详解
Array对象即数组对象用于在单个变量中存储多个值,JS的数组是弱类型的,所以允许数组中含有不同类型的元素,数组元素甚至可以是对象或者其他数组. 创建数组的语法 1.Array构造器 1.var li ...
- tcpcopy 流量复制
依赖 libpcap 线上服务器安装 https://github.com/session-replay-tools/tcpcopy.git 下载后解压 #--pcap-capture 默认raw s ...