似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论。

等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝。

大概思路:在不考虑旋转同构的情况下,正n边形有fib(n+1)+fib(n-1)种染色方法(n==1特判),然后后面就是套公式了,涉及到要用欧拉定理优化,不然会T。(理论的东西看下组合数学书中polya计数部分,及数论书中欧拉函数部分中 n的约数的欧拉函数,感觉看博客不如系统的看看书,再结合一下网上一些比较基础的polya题来理解。)

题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5868

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+;
LL Eular(LL n)
{
LL ret=n;
for(LL i=; i*i<= n; i++)
{
if(n%i==)
{
ret-=ret/i;
while(n%i==) n/= i;
}
}
if(n>) ret-=ret/n;
return ret;
}
LL qpow(LL n,LL k)
{
LL res=;
for(; k; k>>=)
{
if(k&) res=res*n%mod;
n=n*n%mod;
}
return res;
}
LL inv(LL x)
{
return qpow(x,mod-);
}
const LL N=;
struct Mat
{
LL mat[N][N];
};
Mat Mut(Mat a,Mat b)
{
LL i,j,k;
Mat c;
memset(c.mat,,sizeof(c.mat));
for(k=; k<N; k++)
{
for(i=; i<N; i++)
{
if(a.mat[i][k])
for(j=; j<N; j++)
{
if(b.mat[k][j])
c.mat[i][j]=c.mat[i][j]+a.mat[i][k]*b.mat[k][j];
c.mat[i][j]=c.mat[i][j]%mod;
}
}
}
return c;
}
Mat Pow(Mat a,LL n)
{
Mat c;
for(int i = ; i < N; ++i)
for(int j = ; j < N; ++j)
c.mat[i][j] = (i == j);
for(; n; n>>=)
{
if(n&) c=Mut(c,a);
a=Mut(a,a);
}
return c;
}
LL fib(LL x)
{
if(x==) return ;
Mat A;
A.mat[][]=A.mat[][]=A.mat[][]=;
A.mat[][]=;
Mat A_=Pow(A,x-);
return A_.mat[][];
}
LL polya(LL n)
{
if(n==) return ;
LL ans=,i;
for(i=;i*i<n;i++)
if(n%i==)
{
ans=(ans+Eular(i)*(fib(n/i-)+fib(n/i+)))%mod;
ans=(ans+Eular(n/i)*(fib(i-)+fib(i+)))%mod;
}
if(i*i==n) ans+=Eular(i)*(fib(i-)+fib(i+))%mod;
return ans*inv(n)%mod;
}
int main()
{
LL n;
while(cin>>n)
cout<<polya(n)<<'\n';
}

hdu 5868:Different Circle Permutation 【Polya计数】的更多相关文章

  1. HDU 5868 Different Circle Permutation(burnside 引理)

    HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...

  2. HDU 5868 Different Circle Permutation

    公式,矩阵快速幂,欧拉函数,乘法逆元. $an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d ...

  3. 解题:HDU 5868 Different Circle Permutation

    题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...

  4. HDU 5868 Different Circle Permutation Burnside引理+矩阵快速幂+逆元

    题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...

  5. HDU 1817Necklace of Beads(置换+Polya计数)

    Necklace of Beads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  7. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  9. HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)

    Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. loj#2391 「JOISC 2017 Day 1」港口设施

    分析 https://yhx-12243.github.io/OI-transit/records/uoj356%3Bloj2391%3Bac2534.html 代码 #include<bits ...

  2. 535D Tavas and Malekas

    题目大意 给你一个串和m个下标 问你一个长度为n的串每一个下标开始的后缀的前缀都包含给定的串的方案数 分析 对于给定的串求出z数组 对于两个串不重叠的情况就是中间都不包含的数随便填即可 对于重叠的情况 ...

  3. PHP-密码和token

    密码 直接 md5 和 sha1 不安全!!! crypt() 和 hash_equals(): http://php.net/manual/zh/function.crypt.php <?ph ...

  4. python中w和wb文件写入的区别!

    一:基本区别:  w:是文本写入 wb:字节写入 windows中换行符是 \r\n w写入文件的时候,遇到 \n 自动替换成  \r\n

  5. jmeter之ServerAgent监控资源

    对linux服务器的服务进行压测时,服务器的运行情况可以通过添加插件来观察,而不用使用top命令实时的去看 1.资源准备 2.环境准备 3.资源监控 1.资源准备 可通过该网址下载jmeter所有插件 ...

  6. Kestrel web server implementation in ASP.NET Core

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore1x&view ...

  7. 关于 pip disreubution setuptools(unable to locate package pip)

    总是报找不到setuptools模块的错误 很是郁闷 安装pip的前提条件是要安装setuptools 或distribute. 安装distribute的方法: $ curl http://pyth ...

  8. C#后台获取当前时间并格式化

    最常用的:DateTime.Now.ToString("yyyy-MM-dd"); //今天DateTime.Now.Date.ToShortDateString(); //昨天, ...

  9. UI自动化处理文件上传

    UI自动化处理文件上传 import win32guiimport win32con def set_uploader(self, file_path): sleep(2) self.file_pat ...

  10. Map2

    map增加和更新: map["key"] = value //如果key还没有,就是增加,如果key存在就是修改 案例演示: func main() { cities := mak ...