【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[颜色]} ...
随机推荐
- Python阶段复习 - part 3 - Python函数
利用函数打印9*9乘法表 def cheng(num): for i in range(1,num+1): for j in range(1,i+1): print('{0} * {1} = {2}' ...
- win7下安装Linux实现双系统全攻略
http://jingyan.baidu.com/article/c275f6bacc3326e33c756743.html
- skb管理函数之alloc_skb、dev_alloc_skb、kfree_skb、dev_kfree_skb、consume_skb
alloc_skb--分配skb dev_alloc_skb--分配skb,通常被设备驱动用在中断上下文中,它是alloc_skb的封装函数,因为在中断处理函数中被调用,因此要求原子操作(GFP_AT ...
- python基础===self的理解
self是类的实例 self有点类似java中的this,无实际意义.但是约定俗成的都是用self表示类的实例 class A: def func(self): print(self) #指向的是类的 ...
- sicily 1020. Big Integer
Description Long long ago, there was a super computer that could deal with VeryLongIntegers(no VeryL ...
- 【bzoj4373】算术天才⑨与等差数列
同之前那道由乃题,可以认为由乃题是这题的特殊情况…… 维护方法是同样的,维护区间和,区间平方和即可. 注意特判一个数(其实没有必要) #include<bits/stdc++.h> ; u ...
- BZOJ 3771 生成函数,FFT
Description 我们讲一个悲伤的故事. 从前有一个贫穷的樵夫在河边砍柴. 这时候河里出现了一个水神,夺过了他的斧头,说: “这把斧头,是不是你的?” 樵夫一看:“是啊是啊!” 水神把斧头扔在一 ...
- 一个朋友 js图表开发问题 用 c和 js 解决
引言 不求知道一切, 只求发现一件 -- 乔治·西蒙·欧姆 附注:那些存在于梦幻中的事迹,那些儿时梦中的人物,每每看起,都觉得 .哎 .... 岁月 ... 一直在努力 ... ...
- jQuery -《锋利的jQuery》————读后小结
jQuery是一个优秀的javascript库. 我用的是vs2012自带的 jquery-1.8.2.js这个库,在Scripts这个文件夹下面 首先,我们使用jQuery要在head标签内引入j ...
- Can't load standard profile: GRAY.pf
报错: java.lang.IllegalArgumentException: Can't load standard profile: GRAY.pf at java.awt.color.ICC_P ...