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.
Burnside theorem Dafa Good, for any permutation, use backpack DP to find out the program number
P.s. Don't forget to add a non-changing permutation
1#include <cstdio>2#include <cstring>3 intSr, Sb, Sg, N, M, p, a[ -][ -];4 5 intPow_mod (intAintKintm) {6 if(k = =0)return 1;7 if(k = =1)returnAm;8 intret = Pow_mod (A, K/2, m);9RET = RET * RET%m;Ten ifK2==1) ret = ret * A%m; One returnret; A } - - intInvintAintm) { the returnPow_mod (A, M-2, m); - } - - voidinit () { +scanf"%d%d%d%d%d", &SR, &SB, &SG, &m, &p); -n = Sr + Sb +Sg; + for(inti =1; I <= m; i++) A for(intj =1; J <= N; J + +) scanf ("%d", &a[i][j]); atm++; - for(inti =1; I <= N; i++) A[m][i] =i; - } - - intComputeintt) { - intN =0, arr[ -], f[ -][ -][ -]; in BOOLb[ -]; memset (b,0,sizeof(b)); - for(inti =1; I <= N; i++) to if(!B[i]) { + intpos = i, cnt =0; - while(!B[pos]) { theB[pos] =1; cnt++; *pos =A[t][pos]; $ }Panax NotoginsengArr[++n] =CNT; - } theMemset (F,0,sizeof(f)); + intsum =0; Af[0][0][0] =1; the for(inti =1; I <= N; i++) { +Sum + =Arr[i]; - for(intI1 = Sr; I1 >=0; i1--) $ for(intI2 = Sb; I2 >=0; i2--) $ for(inti3 = Sg; i3 >=0; i3--) - if(I1 + i2 + i3 = =sum) { - if(I1 >=Arr[i]) theF[I1][I2][I3] = (F[i1][i2][i3] + f[i1-arr[i]][i2][i3])%p; - if(I2 >=Arr[i])WuyiF[I1][I2][I3] = (F[i1][i2][i3] + f[i1][i2-arr[i]][i3])%p; the if(i3 >=Arr[i]) -F[I1][I2][I3] = (F[i1][i2][i3] + f[i1][i2][i3-arr[i])%p; Wu } - } About returnF[SR][SB][SG]; $ } - - intMain () { - //freopen ("Input.txt", "R", stdin); A //freopen ("Output.txt", "w", stdout); + init (); the intAns =0; - for(inti =1; I <= m; i++) $Ans = (ans + compute (i))%p; theAns = (ans * INV (M, p))%p; theprintf"%d\n", ans); the return 0; the}BZOJ1004
BZOJ1004: [Hnoi2008]cards