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) ...
随机推荐
- [CSP-S模拟测试]:棋盘(数学+高精度)
题目描述 在一个大小为$N\times N$的棋盘上,放置了$N$个黑色的棋子.并且,对于棋盘的每一行和每一列,有且只有一个棋子.现在,你的任务是再往棋盘上放置$N$个白色的棋子.显然,白色棋子不能与 ...
- execute、executeQuery和executeUpdate之间的区别 转
转:http://blog.csdn.net/colin_fantasy/article/details/3898070 execute.executeQuery和executeUpdate之间的区别 ...
- .NETFramework:System.Net.WebClient.cs
ylbtech-.NETFramework:System.Net.WebClient.cs 提供用于将数据发送到和接收来自通过 URI 确认的资源数据的常用方法 1.返回顶部 1. #region 程 ...
- docker 保存镜像 加载镜像
1.保存镜像 docker save -o 保存的文件名 来源镜像 2.加载镜像 docker load -i 保存的文件名
- curl 中关于 CURLINFO_HEADER_SIZE 的 BUG 定位及修复
curl 官方下载页面 CentOS7 默认安装的 curl 版本太低了,需要升级为最新版. 1. 问题描述 对接了一个接口,用来下载 PDF 文件.使用 curl 下载后,文件老是报错无法打开.接口 ...
- 【ABAP系列】SAP SAP中关于编码的解释
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP SAP中关于编码的解释 ...
- Using Tensorflow SavedModel Format to Save and Do Predictions
We are now trying to deploy our Deep Learning model onto Google Cloud. It is required to use Google ...
- 将Java项目打包成可以独立运行的Jar包
因为一直也没怎么用过Java的原因,所以以前本科上课的时候,在控制台下运行Java程序都是仅仅运行单个的没有第三方库依赖的情况下运行的 那种情况特别简单,只要输入Javac 文件名.java等到编译完 ...
- dp(最长升序列)
http://poj.org/problem?id=2533 题意:给你n(1-1000)个数,求这n个数的最长升序列. 题解:dp[i]表示以第i个数结尾的最长升序列. #include & ...
- Spark链接hive时 “HikariCP” 问题
IDE本地调试和spark-shell调试报错: Caused by: org.datanucleus.exceptions.NucleusUserException: The connection ...