http://www.lydsy.com/JudgeOnline/problem.php?id=1004 (Topic link)
Test instructions
n Card, dyed in 3 colors, each color can only dye a fixed number of sheets. Some shuffling schemes are given, and the number of staining schemes is asked.
Solution
Burnside lemma.
Left-turn: LCF
Code
bzoj1004#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <cmath> #define LL long long#define inf 1<<30#define Pi acos ( -1.0) #define Free (a) Freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int maxn=100; LL F[MAXN][MAXN][MAXN],A[MAXN],VIS[MAXN],SIZE[MAXN]; LL n,m,p,r,g,b; ll Power (ll A,ll b) {ll res=1;while (b) {if (b&1) res=res*a%p;a=a*a%p;b>>=1;} return res;} LL dp () {memset (vis,0,sizeof (Vis)), memset (F,0,sizeof (f)); int cnt=0;for (int i=1;i<=n;i++) if (!vis[i]) {size[++cnt] =0;for (int j=a[i];! VIS[J];J=A[J]) vis[j]=1,size[cnt]++;} f[0][0][0]=1;for (int i=1;i<=cnt;i++) for (int r=r;r>=0;r--) for (int. b=b;b>=0;b--) for (int g=g;g>=0;g--) {if (R>=size[i]) f[r][b][g]= (F[r][b][g]+f[r-size[i]][b][g])%p;if (B>=size[i]) f[r][b][g]= (f[r][b][g]+f[r][ B-SIZE[I]][G])%p;if (G>=size[i]) f[r][b][g]= (F[r][b][g]+f[r][b][g-size[i]])%P;} return f[r][b][g]%p;} int MAIn () {scanf ("%lld%lld%lld%lld%lld", &r,&b,&g,&m,&p); n=r+b+g; LL ans=0;for (int i=1;i<=n;i++) a[i]=i;ans= (ANS+DP ())%p;for (int i=1;i<=m;i++) {for (int j=1;j<=n;j++) scanf ("% LLD ", &a[j]); ans= (ANS+DP ())%P;} Ans*=power (m+1,p-2);p rintf ("%lld", ans%p); return 0;}
"Bzoj1004" Hnoi2008-cards