[HNOI2008] Cards (dp, Burnside lemma)

Burnside lemma:

Reference from  a big brother to explain to Burnside lemma and Polya theorem

Related concepts

  1. Group: in mathematics, has to meet the group represents a closure, is associative, unital, algebraic structure of the inverse element of the binary operation.
  2. Permutation groups: group substitution of each element being constituted by a finite set.

A replacement of similar form

 

Then Burnside lemma:

(1) metaphysical Description

In one permutation group G = {a1, a2, a3 ...... ak}, the product is written to each permutation are disjoint cycle.

A C1 set (ak) is the number of displacement under the action of ak fixed point, that is, the cycle length is the number 1.

After the conversion by the above operation may be replaced with equal elements belonging to the same equivalence class

Then the equivalence class number is equal to:

 

That replacement average for each permutation of fixed points of group

(2) understanding of the formula

eg: a square divided into four cells, two colored, how many kinds of programs? Wherein rotation of the same image after operator the same program.

 

On rotation, a total of four replacement method, that is, | G | = 4

Fixed (360 °): a1 = (1) (2) ... (16)

90 degrees counter-clockwise: a2 = (1) (2) (3 4 5 6) (7 8 9 10) (11 12) (13 14 15 16)

90 degrees clockwise: a3 = (1) (2) (6 5 4 3) (10 9 8 7) (11 12) (16 15 14 13)

180 degrees: a4 = (1) (2) (3 5) (4 6) (7 9) (8 10) (11) (12) (13 15) (14 16)

Understanding of brackets: Suppose rotatably (not move counterclockwise 90 degrees, 90 degrees clockwise, 180 degrees) to the + operator. + Represents the counter-clockwise 90 degrees, brackets (3456) shows a (3 + 4 + 5 + 6 +) as one cycle, i.e., (+ 3 + 4 + 5 + 6) = 3 (return to the origin) ;

Then we each way for replacement, find the fixed point of them, that is, only to their own situation

It made of Burnside, a total of (16 + 2 + 2 + 4) / 4 = 6 (embodiment)

Polya Theorem

 

Mention mentioning that Polya Theorem I do not understand it (come back someday understand the explanation)

 

Polya theorems actually concrete, a fixed point calculation of a specific method of Burnside:

Suppose there is a substitution x03C3 # &; K " > [sigma] k cycles, the rotation is 

easy to know all the positions corresponding to each cycle must be the same color, and what color is selected independently of each other between any two cycles. 

Thus, if there are m types colors, replacing the corresponding fixed point number is m & # x03C3; K " > ^ m [sigma] k. 

Replacement of Burnside with which the C (G) " > C (G), i.e. C (G) = MK " > C (G) = m ^ K. The number of equivalence classes is obtained:

This question is by now learn to use Burnside lemma

[HNOI2008]Cards(luogu)

 

  • Description

 

Title Description

 

Xiaochun now be less busy, facing N cards on the desk, he decided to give each stain, Xiaochun currently only three colors: red, blue, green, he asked how many staining protocols Sun, Sun will be given soon the answer.

 

Further, Sr Zhang Xiaochun requirements dyed red, Sb Zhang blue, Sg green sheets. He also asked how many kinds of programs, Sun thought for a moment, then gives the correct answer. Finally Xiaochun invented the M different shuffling method , Sun where he asked how many different staining protocols same two staining methods if and only if one can be shuffled by any method (i.e., shuffling may be used various methods, but each method can be used multiple times) wash into another.

 

Sun discovered the problem a little more difficult, the decision to you, the answer may be large, as long as the remainder obtained by dividing the answer of P (P is a prime number).

 

Input Format

 

第一行输入 5 个整数:Sr,Sb,Sg,m,p(m<=60,m+1<p<100)。n=Sr+Sb+Sg。接下来 m 行,每行描述一种洗牌法,每行有 n 个用空格隔开的整数 X1X2...Xn,恰为 1 到 n 的一个排列,表示使用这种洗牌法,第 i位变为原来的 Xi位的牌。输入数据保证任意多次洗牌都可用这 m种洗牌法中的一种代替,且对每种

 

洗牌法,都存在一种洗牌法使得能回到原状态。

 

100%数据满足 Max{Sr,Sb,Sg}<=20。

 

输出格式

 

不同染法除以P的余数

  • Solution

运用01背包求出每一种置换(注意不动也是一种置换)的不动点个数,再运用Burnside引理求出等价类个数

  • Code

 

#include <cstdio>
#include <cstdlib>
#include <cstring>
#define ll long long
using namespace std;
int s1,s2,s3,m,a[100][100],size[100],tot,n;
ll p,f[21][21][21],ans;
bool vis[100];
ll ksm(ll a,int b)//快速幂求逆元 
{
    ll x=a,ans=1;
    while(b)
    {
        if(b&1) ans=(ans*x)%p;
        x=(x*x)%p,b>>=1;
    }
    return ans;
}
ll Dp(int x)//01背包 
{
    memset(vis,false,sizeof(vis));
    memset(f,0,sizeof(f));
    tot=0;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            vis[i]=true,size[++tot]=1;
            int p=i;
            while(!vis[a[x][p]]) vis[p=a[x][p]]=true,size[tot]++;
        }
    f[0][0][0]=1;
    for(int i=1;i<=tot;i++)
        for(int j1=s1;j1>=0;j1--)
            for(int j2=s2;j2>=0;j2--)
                for(int j3=s3;j3>=0;j3--)
                {
                    if(j1>=size[i]) f[j1][j2][j3]=(f[j1][j2][j3]+f[j1-size[i]][j2][j3])%p;
                    if(j2>=size[i]) f[j1][j2][j3]=(f[j1][j2][j3]+f[j1][j2-size[i]][j3])%p;
                    if(j3>=size[i]) f[j1][j2][j3]=(f[j1][j2][j3]+f[j1][j2][j3-size[i]])%p;
                }
    return f[s1][s2][s3];
}
int main()
{
    scanf("%d%d%d%d%lld",&s1,&s2,&s3,&m,&p);
    n=s1+s2+s3;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            scanf("%d",&a[i][j]);
    m++;
    for(int i=1;i<=n;i++) a[m][i]=i;
    for(int i=1;i<=m;i++)
        ans=(ans+Dp(i))%p;//Burnside引理
    printf("%lld\n",ans*ksm((long long)m,p-2)%p);
    return 0;
}

Guess you like

Origin www.cnblogs.com/hsez-cyx/p/12221207.html