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的更多相关文章

  1. 【BZOJ 1005】【HNOI 2008】明明的烦恼

    http://www.lydsy.com/JudgeOnline/problem.php?id=1005 答案是\[\frac{(n-2)!}{(n-2-sum)!×\prod_{i=1}^{cnt} ...

  2. 【BZOJ 1043】【HNOI 2008】下落的圆盘 判断圆相交+线段覆盖

    计算几何真的好暴力啊. #include<cmath> #include<cstdio> #include<cstring> #include<algorit ...

  3. 【BZOJ 1007】【HNOI 2008】水平可见直线 解析几何

    之前机房没网就做的这道题,用的解析几何判断交点横坐标 #include<cmath> #include<cstdio> #include<cstring> #inc ...

  4. 【BZOJ 1004】 1004: [HNOI2008]Cards (置换、burnside引理)

    1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有多少种染色方案,Sun很 ...

  5. 【BZOJ 1004】 [HNOI2008]Cards

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 [题意] 给你sr+sb+sg张牌,(令n=sr+sb+sg),让你把这n张牌染 ...

  6. 【HNOI 2008】 越狱

    [题目链接] 点击打开链接 [算法] 显然,越狱情况数 = 总情况数 - 不能越狱的情况数 很容易发现,总情况数 = M^N 不能越狱的情况数怎么求呢? 我们发现,不能越狱的情况,其实就是第一个人任选 ...

  7. 【BZOJ】【1004】【HNOI2008】Cards

    Burnside/Polya+背包DP 这道题目是等价类计数裸题吧……>_> 题解:http://m.blog.csdn.net/blog/njlcazl_11109/8316340 啊其 ...

  8. [BZOJ 1004] [HNOI2008] Cards 【Burnside引理 + DP】

    题目链接:BZOJ - 1004 题目分析 首先,几个定义和定理引理: 群:G是一个集合,*是定义在这个集合上的一个运算. 如果满足以下性质,那么(G, *)是一个群. 1)封闭性,对于任意 a, b ...

  9. 【BZOJ】3052: [wc2013]糖果公园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]} ...

随机推荐

  1. 【NOIP】提高组2012 疫情控制

    [题意]n个点的树,1为根,要求删除一些点使得截断根节点和所有叶子结点的路径(不能删根,可以删叶子).有m支军队在m个点上,每时刻所有军队可以走一步,最终走到的地方就是删除的点,求最短时间. [算法] ...

  2. quick-cocos2dx lua中读取 加密 csv表

    我非常想把一些非必需的信息以CSV表的格式保存到客户端,以减少和服务器的通讯,降低压力.于是写了这么一个. 但因为大家觉得这样的话,需要每次登陆时来检测同步这些数据,会减慢登陆速度,于是没有用到. 我 ...

  3. JS对象操作

    一.String常用操作 1.截取 substr(start,length) //返回从指定位置开始的指定长度的字符串. substring(start,end) //返回两个指定的位置之间的字符串. ...

  4. Cordova入门

    创建你的第一个App 因为对接要对接酷音,实现h5跨平台调用客户端的保存和分享功能,所以学了下cordova的入门. 安装Cordova CLI Cordova命令行工具作为npm包分发. 安装cor ...

  5. JVM在遇到OOM(OutOfMemoryError)时生成Dump文件

    方法一: 命令:jmap -dump:format=b,file=heap.bin file:保存路径及文件名pid:进程编号(windows通过任务管理器查看,linux通过ps aux查看) du ...

  6. 使用GDB命令行调试器调试C/C++程序【转】

    转自:https://linux.cn/article-4302-1.html 编译自:http://xmodulo.com/gdb-command-line-debugger.html作者: Adr ...

  7. 网络设备之pci_device_id

    标准PCI设备都有一个配置寄存器,用来存储各种参数: /* pci设备配置寄存器 */ struct pci_device_id { /* 厂商id,设备id */ __u32 vendor, dev ...

  8. monkey测试===monkeyrunner测试教程(2)

    我先引入一段代码: #test.py from com.android.monkeyrunner import MonkeyRunner as mr device=mr.waitForConnecti ...

  9. leetcode之Ransom Note

    题目描述: 
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  10. mac date 和 Linux date实现从指定时间开始循环

    Linux date begin="2016-01-01" ; i < ; i++ )); do current=$(date -d "$i day $begin& ...