1004: [Hnoi2008]cards time limit:10 Sec Memory limit:162 MB
submit:2163 solved:1286
[Submit] [Status] [Discuss] Description
Koharu is now very quiet, facing the desk of the n cards, he decided to give each stain, the current Koharu only 3 colors: red, blue, green. He asked Sun how many kinds of staining options he had, and sun quickly gave the answer. Further, Koharu asked to dye SR red, SB-Blue, SG Zhang. He asked how many options he had, and sun thought about it and gave the correct answer. Finally Koharu invented M different shuffle methods, where he asked Sun how many different staining schemes. Two staining methods are the same when and only if one of them can be used by arbitrary shuffle method (that is, you can use a variety of shuffle method, and each method can be used several times) to 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 shuffling method, each line has n a space separated by the integer x1x2 ... Xn, just a permutation of 1 to N, represents the use of this shuffling method,
The first bit becomes the card of the original XI position. Input data to ensure that any number of shuffle can be used in this m shuffle method of a substitution, 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 Input1 1 1) 2 7
2 3 1
3 1 2Sample Output2HINT
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.
Source
The puzzle: Mom, I will replace the group! Fast film cyx!!!
Burnside theorem: There is m displacement k color, all the essential different number of staining schemes is the average number of invariant elements of each permutation. The so-called invariant element is a dyeing scheme that has been transformed and changed before the change. So now is the need to ask for a constant element, but also to meet the limits of the number of colors. The rotation of the permutation must be a color in the invariant element, which can then be used for a three-dimensional 01 knapsack scheme number. Finally, write an inverse of the yuan just fine.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= -+Ten, maxm= -+5, inf=-1u>>1; One intZ[maxn],s[maxn],f[maxm][maxm][maxm],scnt,sr,sg,sb,m,mod,n;BOOLVIS[MAXN]; A voidAddint&a,intb) {a= (a+b)%MoD;} - intCalc () { -Memset (F,0,sizeof(f)); thememset (Vis,false,sizeof(Vis)); -memset (s),0,sizeof(s)); -Scnt=0; - for(intI=1; i<=n;i++)if(!Vis[i]) { +scnt++; for(intj=i;! VIS[J];J=Z[J]) vis[j]=true, s[scnt]++; -}f[0][0][0]=1; + for(intI=1; i<=scnt;i++) A for(intr=sr;r>=0; r--) at for(intg=sg;g>=0; g--) - for(intb=sb;b>=0; b--){ - if(R>=s[i]) Add (f[r][g][b],f[r-S[i]] [G] [b]); - if(G>=s[i]) Add (f[r][g][b],f[r][g-S[i]] [b]); - if(B>=s[i]) Add (f[r][g][b],f[r][g][b-S[i]]); - } in returnF[SR][SG][SB]; - } to voidEXGCD (intAintBint&x,int&y) { + if(b==0) {x=1; y=0;return;} EXGCD (B,a%b,x,y);intt=x;x=y;y=t-a/b*y; - } the intIneintT) { * intX,Y;EXGCD (t,mod,x,y); x%=mod; while(x<=0) X+=mod;returnx; $ }Panax NotoginsengInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); the while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} + while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); A returnx*=Sig; the } +InlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; $ intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; $ for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - voidinit () { theSr=read (); Sg=read (); Sb=read (); M=read (); mod=read (); -N=SR+SG+SB;intans=0;Wuyi for(intTime=1; time<=m;time++){ the for(intI=1; i<=n;i++) z[i]=read (); - Add (Ans,calc ()); Wu } - for(intI=1; i<=n;i++) z[i]=i; AboutAdd (Ans,calc ()); Write (Ans*ine (m+1)%MoD); $ return; - } - voidWork () { - return; A } + voidprint () { the return; - } $ intMain () {init (); work ();p rint ();return 0;}
Bzoj 1004 [Hnoi2008]cards