polya定理适用于染色问题方案数问题。
举个栗子:
poj1286 Necklace of Beads
当n = 4时,可顺时针旋转0、1、2、3格
0格:(1)(2)(3)(4)互相变化
1格:(1,2,3,4)互相变化
2格:(1,3)(2,4)互相变化
3格:(1,2,3,4)互相变化
用3种颜色染色,answer = (1/4) * (3^4+3^1+3^2+3^1)=24
当n = 5时,answer = (1/5) * (3^5+3^1*4)=51
以此类推。
下面是对称。
当n = 4时,有4条对称轴
其中2条,(1,2)(3,4)互相变化
另2条,(1)(3)(2,4)互相变化
answer= (1/4) * (2*3^2+2*3^3)=18
当n = 5时,有5条对称轴
每一条,(1)(2,5)(3,4)
answer=(1/5) * (5*3^3)=27
以此类推。
最终answer =( 旋转+对称)/ 2。
ll gcd(int a,int b)
{
if(b==0)return a;
return gcd(b,a%b);
}
ll quick(int x,int y)
{
ll sum=1;
while(y)
{
if(y%2==1)
{
sum*=x;
}
x*=x;
y/=2;
}
return sum;
}
ll opp()
{
if(m%2==0)
{
return ((m/2)*(quick(n,m/2)+quick(n,(m-2)/2+2)))/m;
}else
{
return quick(n,(m-1)/2+1);
}
}
ll turn()
{
ll ans=quick(n,m);
for(int i=1;i<m;i++)
{
ans+=quick(n,gcd(i,m));
}
return ans/m;
}