Reference: Polay Theorem
I feel that this kind of problem has always been easy to meet recently.
First, a theorem is summarized as follows:
The simplest example is used to describe
Color the square matrix of 2*2 in black and white. How many different images can be obtained? The two schemes that match them by rotation are the same.
Set G = {p1, p2 ,..., PG} is a replacement group on Ω, for example, the replacement group G = {to 0 °, to 90 °, to 180 °, to 270 °}
C (PK) is the number of cycles for replacing the PK
The cyclic section of G1 replacement {to 0 °} is 4, {(1), (2), (3), (4 )}
The cyclic section of G2 replacement {to 90 °} is 1 )}
The cyclic section of G3 replacement {to 180 °} is 2 )}
The cyclic section of G4 replacement {to 270 °} is 1. {(1, 2, 3, 4 )}
Use the color in m to color the elements in Ω,
The number of coloring schemes is L = 1/| G | * [C1 (P1) + C1 (P2) + C1 (P3) +... C1 (P [g])]
= 1/| G | * [m ^ C (P1) + m ^ C (P2) + m ^ C (P3) +... m ^ C (P [g])]
| G | represents the total number of replicas and the number of colors in MB.
C1 (PI) refers to the number of fixed points for pi replacement (that is, the number of points with a cyclic node of 1)
Obviously, the four numbers are 16, 2, 4, and 2, respectively.
L = 1/| G | * [16 + 2 + 4 + 2] = 6
C (PI) refers to the number of cycles that replace pi.
L = 1/| G | * [2 ^ 4 + 2 ^ 1 + 2 ^ 2 + 2 ^ 1] = 6
Let's start with a simple question:
Poj 2409: http://poj.org/problem? Id = 2409
Question:
A necklace company produces bracelets. N beads form a ring, with M color to N beads dyeing, you get a variety of bracelets. However, after rotation and flip, the same solution is used.
For example, if you use two colors to dye 5 beads, the formula is 8.
Solution:
I. rotation (for example, if there are n beads, the rotation angle is 360/n each time)
2: Flip (considering the symmetric axis, an odd number of beads, each time the symmetric axis can pass through a bead, a total of N symmetric axes)
Even Number of beads, each symmetric axis is two beads, a total of n/2 symmetric axis, or each symmetric axis does not pass through the beads, such a symmetric axis is n/2
Therefore, whether it is an odd or even number, there are 2 * n flip methods.
It can be proved that each cyclic section is gcd (I, n) 0 <I <= N
# Include <iostream> # include <stdio. h> # include <string. h> # include <math. h> using namespace STD; int gcd (int A, int B) {return B = 0? A: gcd (B, A % B);} long rotate (INT C, int N) {// rotate (360/N) * I degree long sum = 0; For (INT I = 1; I <= N; I ++) sum + = POW (C * 1.0, gcd (n, i); // the cycle of each rotation is gcd (n, I) Return sum;} Long turn (INT C, int N) {// flip long sum = 0; If (N % 2) sum + = N * POW (C * 1.0, (n + 2)/2 ); // If the odd number is exceeded, the symmetric axes are all passed through a bead. A total of N cyclic segments for each replacement are n/2 + 1 else sum + = n/2 * (POW (C * 1.0, n/2) + POW (C * 1.0, (n + 2)/2 )); // even number is passed through the beads or n/2 cycles without passing through the beads. n/2 + 1 and N/2 can be calculated using the following formula: Return sum ;} void polyA (int c, int N) {int I, j; long sum = 0; sum + = rotate (C, N); sum + = turn (C, n); printf ("% LLD \ n", sum/(2 * n);} int main () {int n, m; while (scanf ("% d", & N, & M), N | M) {polyA (n, m);} return 0 ;}
# Include <cstring> # include <string> # include <fstream> # include <iostream> # include <iomanip> # include <cstdio> # include <cctype> # include <algorithm> # include <queue> # include <map> # include <set> # include <vector> # include <stack> # include <ctime> # include <cstdlib> # include <functional> # include <cmath> using namespace STD; # define PI ACOs (-1.0) # define EPS 1e-7 # define INF 0x7fffffffff # define llinf 0x7fffffffffffffffff # define seed 13 13131 # define mod 1000000007 # define ll long # define ull unsigned ll # define lson L, M, RT <1 # define rson m + 1, R, RT <1 | 1 // cyclic section for replacement, polyA principle // perm [0 .. n-1] is 0 .. one replacement (Arrangement) of N-1 // returns the minimum replacement cycle. Num returns the number of cyclic nodes # define maxn 1000int gcd (int A, int B) {return B? Gcd (B, A % B): A;} int polyA (int * perm, int N, Int & num) {int I, j, P, V [maxn] = {0}, ret = 1; for (num = I = 0; I <n; I ++) if (! V [I]) {for (Num ++, j = 0, P = I ;! V [p = perm [p]; j ++) V [p] = 1; RET * = J/gcd (Ret, J);} return ret ;} int main () {int perm1 [6] = {,}; int perm2 [6] = {,}; int num; cout <polyA (perm2, 6, num) <Endl; cout <num <Endl ;}
Polay theorem Summary