[Bzoj 1004] [HNOI2008] Cards "Burnside lemma + DP"

Source: Internet
Author: User

Title Link: BZOJ-1004

Problem analysis

First, several definitions and theorem lemma:

Group: G is a set, * is an operation defined on this set.

If the following properties are met, then (G, *) is a group.

1) closed, for any A, b belongs to G, A * B belongs to G

2) Binding law, A * b * c = a * (b * c)

3) unit element, in G there is a unit E, so that for any A in G, a * e = e * a = a

4) inverse, for any of a in G, there is a B in G, so that A * b = e, where b is called a inverse element

For example, an integer addition in a number meaning is a group.

The group that satisfies the commutative law is the commutative group, also called the abelian group.

Replacement: Can be used (A1, B1, A2-A, ...,-A-and bn) to represent a permutation in which A1, ..., an and B1, ..., Bn are all 1 to n an arrangement;

If some permutations and their stacking operations form a group, they are called a permutation group.

Burnside lemma in permutation group: if the position of 1 to n is to be stained according to certain requirements, then the number of different staining schemes is the average of the number of fixed staining schemes for each permutation in the permutation group.

To explain the following, essentially different staining schemes mean that two staining schemes cannot be identical by any permutation transformation in a permutation group, and they are essentially different.

The number of fixed staining schemes for a permutation is a staining scheme that has not changed after the substitution transformation.

Then we are asking for the number of fixed staining schemes for each permutation.

Polya theorem tells us that if it is dyed with k color, then for displacement p, the number of its fixed staining scheme is k^ (L (P)), where L (p) is the number of cyclic sections of displacement p.

This is very well understood, because each cycle section should be dyed the same color in the cycle section if it is to make the replacement unchanged.

However, the coloring requirement of this problem is that given the number of 3 colors, it is not possible to use k^ (L (P)) to beg.

We use a 3-D DP, or we'll search through it to find out the size of all the loop sections of the permutation. Then treat each cycle as an item and dye a color.

Using f[i][j][k] to dye the first items, the 1th color with J, the 2nd color with K-Times dyeing program number.

One more thing to note about this problem is that you need to add a permutation that does not change as a unit element to become a permutation group.

The number of fixed staining schemes for this unit element is the number of all staining schemes, which are arranged directly with multiple sets, n! /(a! b! c!).

Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath > #include <algorithm>using namespace std;const int maxn = 60;int Na, Nb, Nc, N, M, Mod, Ans, Top;int A[MAXN], v[m AxN], SUM[MAXN], f[maxn][maxn][maxn];bool used[maxn];inline int Pow (int a, int b) {int ret = 1, f = a;while (b) {if (b &am P 1) {ret *= f;ret%= Mod;} b >>= 1;f *= F; f%= Mod;} return ret;} inline int NY (int x) {return Pow (x, Mod-2);} void DFS (int x, int Num) {if (used[x]) {v[++top] = Num;return;} USED[X] = True;dfs (A[x], Num + 1);} inline int Fac (int x) {int ret = 1;for (int i = 1; i <= x; ++i) {ret *= i;ret%= Mod;} return ret;} int main () {scanf ("%d%d%d%d%d", &na, &AMP;NB, &nc, &m, &mod); n = Na + Nb + Nc; Ans = FAC (n) * NY (FAC (Na))% mod * NY (FAC (NB))% mod * NY (FAC (NC))% mod;for (int i = 1; I <= m; ++i) {for (int j = 1; J <= N; ++J) {scanf ("%d", &a[j]); USED[J] = false;} Top = 0;for (int j = 1; j <= N; ++j) if (! USED[J]) DFS (j, 0); Sum[0] = 0;for (int j = 1; J <= top; ++j) sum[j] = Sum[j-1] + v[j];f[0][0][0] = 1;for (int j = 1; J <= top; ++j) { for (int p = 0; p <= Na, ++p) {for (int q = 0; q <= Nb; ++q) {F[j][p][q] = 0;if (P >= v[j]) {F[j][p][q] + = F[j-1 ][P-V[J]][Q];F[J][P][Q]%= Mod;} if (q >= v[j]) {F[j][p][q] + = f[j-1][p][q-v[j]];f[j][p][q]%= Mod;} if ((Sum[j]-p-q) >= V[j]) {F[j][p][q] + = f[j-1][p][q];f[j][p][q]%= Mod;}} } Ans + = F[top][na][nb]; Ans%= Mod;} Ans *= NY (M + 1); Ans%= mod;printf ("%d\n", ans); return 0;}

  

[Bzoj 1004] [HNOI2008] Cards "Burnside lemma + DP"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.