【BZOJ1004】【HNOI2008】Cards(群论、Burnside引理、背包dp)

Description

click me

Solution

2.1

由于题目有:

保证任意多次洗牌都可用这 m种洗牌法中的一种代替,且对每种洗牌法,都存在一种洗牌法使得能回到原状态。

所以加上原状态,一共有$m+1$种置换,考虑用$Burnside$引理,剩下的问题只有计算当知道有多少个循环,每个循环的大小时,求不变元的个数。这个用将每个循环看成物品、背包dp解决即可。

2.2

网上有题解说答案就是$$\frac{1}{m+1}\times \frac{(sb+sg+sr)!}{sb!+sg!+sr!}$$我也不知道为什么啊。。

Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**************************************
* Au: Hany01
* Date: Feb 2nd, 2018
* Prob: BZOJ1004 & HNOI2008 Cards
* Email: hany01@foxmail.com
**************************************/
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define fir first
#define sec second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
inline int read()
{
register int _, __; register char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
inline void File()
{
#ifdef hany01
freopen("bzoj1004.in", "r", stdin);
freopen("bzoj1004.out", "w", stdout);
#endif
}
const int maxn = 65;
int sr, sb, sg, n, cnt, Rep[maxn], Mod, m, sz, mp[maxn], vis[maxn], dp[maxn][maxn][maxn], Ans, t;
inline int Pow(int a, int b) {
int Ans = 1;
for ( ; b; b >>= 1, a = a * a % Mod) if (b & 1) (Ans *= a) %= Mod;
return Ans;
}
inline void mod(int &x) { if (x >= Mod) x -= Mod; }
inline void Calc()
{
Set(dp, 0), dp[0][0][0] = 1;
For(l, 1, cnt) Fordown(i, sr, 0) Fordown(j, sb, 0) Fordown(k, sg, 0) {
if (i >= Rep[l]) mod(dp[i][j][k] += dp[i - Rep[l]][j][k]);
if (j >= Rep[l]) mod(dp[i][j][k] += dp[i][j - Rep[l]][k]);
if (k >= Rep[l]) mod(dp[i][j][k] += dp[i][j][k - Rep[l]]);
}
mod(Ans += dp[sr][sb][sg]);
}
int main()
{
File();
sr = read(), sb = read(), sg = read(), n = sr + sb + sg, m = read(), Mod = read();
For(T, 1, m) {
For(i, 1, n) mp[i] = read();
Set(vis, 0), cnt = 0;
For(i, 1, n) if (!vis[t = i]) {
sz = 0;
while (!vis[t]) vis[t] = 1, t = mp[t], ++ sz;
Rep[++ cnt] = sz;
}
Calc();
}
For(i, 1, cnt = n) Rep[i] = 1;
Calc();
printf("%d\n", Ans * Pow(m + 1, Mod - 2) % Mod);
return 0;
}
Contents
  1. 1. Description
  2. 2. Solution
    1. 2.1. 2.1
    2. 2.2. 2.2
  3. 3. Source Code