[bzoj1004] [HNOI2008] [Cards] (Permutation group +burnside lemma + dynamic Programming)

Source: Internet
Author: User

Description

Koharu is now very quiet, facing the desk of n cards, he decided to give each stain, currently Koharu only 3 colors: red, blue, green. He asked Sun
The number of staining schemes sun soon gave the answer. Further, the Koharu request to dye the SR Zhang Red, SB Zhang Blue, the SG Zhang. He asked how many kinds of parties
Case, Sun thought about it and gave the correct answer. Finally Koharu invented M different shuffle methods, where he asked Sun how many different dyeing schemes.
The two staining methods are the same when and only if one can be used by arbitrary shuffle method (that is, you can use a variety of shuffle method, and each method can be used multiple) wash
into another. Sun found the problem a bit difficult, and decided to give it to you, the answer may be very large, just ask for the answer divided by the remainder of P (p is prime).

Input

The first line enters 5 integers: sr,sb,sg,m,p (m<=60,m+1<p<100). N=SR+SB+SG.
Next m line, each line describes a shuffle method, each line has n spaces separated by a number of integers x1x2 ... Xn, just a permutation of 1 to N,
Represents the use of this shuffle method, the first bit into the original XI position of the card. Input data to ensure that any number of shuffle can be used in this M-shuffle method of a generation
, and for each shuffle method, there is a shuffling method so that can return to the original state.

Output

The remainder of the different dyes divided by P

Sample Input
1 1 1 2 7 2 3 1 3 1 2
Sample Output
2
HINT

There are 2 essentially different staining methods RGB and RBG, using shuffle method 2,311 times can get GBR and BGR, using shuffle method 3,121 times can get BRG

and GRB.

100% data satisfies max{sr,sb,sg}<=20.

Solution

The standard permutation group problem

There is a god Ben said, permutation group is not Burnside is Polya

The application of Burnside Lemma can be judged as the solution is essentially different dyeing schemes.

Burnside lemma:

Set G={A1,A2,... AG} is the permutation group on the target set [1,n]. Each permutation is written as the product of the disjoint loop. Is the number of fixed points under the action of the substitution AK, that is, the number of loops with a length of 1. Elements that can be equal after the transformation operation of the above permutation belong to the same equivalence class. If g divides [1,n] into L equivalence class, then: The number of equivalence classes is: For this problem, first look at the equivalent of the limited title: "The two dyeing methods are the same when and only if one of them can pass arbitrary shuffle method", and then look at the sample description, you can know that the marking is useless, and only the order of different so Each loop can derive an equivalence class when and only if the loop section is 1 and the condition is 1, the element within the loop is the same color (after all, the label is useless) so we only ask for the number of elements with a loop section of 1. We consider dynamic programming, a backpack, from large to small enumeration can be guaranteed not to repeat the calculation , we can finally find out the number of corresponding cards in the same number of scenarios. Finally, because the modulo operation can not handle division, we do a multiplication inverse
#include <stdio.h>#include<memory.h>inlineintRin () {intx=0, C=getchar (), f=1;  for(;c< -|| C> $; c=GetChar ())if(! (c^ $)) f=-1;  for(;c> -&&c< -; c=GetChar ()) x= (x<<1) + (x<<3) +c- -; returnx*F;}BOOLb[ A];ints[4],n,m,md,fur[ A][ A],d[ A],f[ +][ +][ +],ans;intdpintx) {memset (b,0,sizeof(b)); inttop=0, V;  for(intI=1; i<=n;i++)        if(!B[i]) {B[i]=1; d[++top]=1; V=i;  while(!B[fur[x][v]]) B[fur[x][v]=1, D[top]++, v=Fur[x][v]; } memset (F,0,sizeof(f)); f[0][0][0]=1;  for(intk=1; k<=top;k++)         for(intdx=s[1];d x>=0;d x--)         for(intdy=s[2];d y>=0;d y--)         for(intdz=s[3];d z>=0;d z--) (DX&GT;=D[K]? (f[dx][dy][dz]= (F[dx][dy][dz]+f[dx-d[k]][dy][dz])%MD):0), (Dy&GT;=D[K]? (f[dx][dy][dz]= (F[dx][dy][dz]+f[dx][dy-d[k]][dz])%MD):0), (Dz&GT;=D[K]? (f[dx][dy][dz]= (F[dx][dy][dz]+f[dx][dy][dz-d[k])%MD):0); returnf[s[1]][s[2]][s[3]];}voidEXGCD (intAintBint&x,int&y) {    if(!B) {x=1; y=0;return;} EXGCD (B,a%b,x,y); intt=x;x=y;y=t-a/b*y;}intMain () { for(intI=1; i<=3; i++) S[i]=Rin (), n+=S[i]; M=rin (), md=Rin ();  for(intI=1; i<=m;i++)         for(intj=1; j<=n;j++) Fur[i][j]=Rin (); M++;  for(intI=1; i<=n;i++) Fur[m][i]=i;  for(intI=1; i<=m;i++) ans= (ANS+DP (i))%MD; intx, y;    EXGCD (M,md,x,y);  while(x<=0) x+=md,y-=m; printf ("%d\n", ans*x%MD); return 0;}

[bzoj1004] [HNOI2008] [Cards] (Permutation group +burnside lemma + dynamic Programming)

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.