hdu 5868:Different Circle Permutation 【Polya计数】
似乎是比较基础的一道用到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计数】的更多相关文章
- HDU 5868 Different Circle Permutation(burnside 引理)
HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...
- HDU 5868 Different Circle Permutation
公式,矩阵快速幂,欧拉函数,乘法逆元. $an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d ...
- 解题:HDU 5868 Different Circle Permutation
题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...
- HDU 5868 Different Circle Permutation Burnside引理+矩阵快速幂+逆元
题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...
- HDU 1817Necklace of Beads(置换+Polya计数)
Necklace of Beads Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 ...
- 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) ...
随机推荐
- layoutSubviews 详解
ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ------- - (void)layoutSubview ...
- <!DOCTYPE>是什么
所有浏览器都支持<!DOCTYPE> 概念 是指web浏览器关于页面使用哪个html版本进行编写的指令. 常用DOCTYPE声明 html 5 <!DOCTYPE html> ...
- hypermesh生成MNF柔性体
软件HyperworksX 2019: 该版本默认的是optistruct模板 1.导入几何→分网→材料定义(注意单位,建议统一mks单位制)→定义单元属性→创建刚性单元: 2.创建load coll ...
- Packet Tracer基本使用
Cisco Packet Tracer基本使用 1:添加设备:路由器选择1841,交换机选择2960二层交换机,添加PC.服务器Server(End Devices) 2:添加连接:这里指以太网连接, ...
- PHP的重载-使用魔术方法实现
摘录PHP官网对PHP重载的解释: PHP所提供的"重载"(overloading)是指动态地"创建"类属性和方法.我们是通过魔术方法(magic method ...
- Jupyter Notebook 快捷键(基本)
Jupyter Notebook 快捷键 Jupyter Notebook 有两种键盘输入模式.编辑模式,允许你往单元中键入代码或文本:这时的单元框线是绿色的.命令模式,键盘输入运行程序命令:这时的单 ...
- websocket初体验
(function (window) { var wsUri = "ws://echo.websocket.org:9150"; var output; MyWebSocket = ...
- Win10.资料
1.Win10版本consumer editions和business editions有什么区别?(http://www.winwin7.com/JC/10722.html) 2.密钥 win10 ...
- 配置NAT实验
实验拓扑: 下面先配置静态NAT:(将私网地址转为公网地址)内部地址到外部地址的1对1转换 1.先配置出口静态路由,指向公网入口路由器 2.nat static命令配置1对1的IP地址转换 3.测试: ...
- hive 取排行第二的工资
CREATE TABLE employee( id INT , salary INT ); INSERT INTO employee , UNION ALL , UNION ALL ,; SELECT ...