题目链接:http://poj.org/problem?id=2409

题意:输入 m, n 表示有 m 种颜色,要构造一个长度为 n 的手环,旋转和对称的只算一种,问能组成多少个不同的手环.

思路:polya 模板

详见:http://m.blog.csdn.net/thchuan2001/article/details/65653855

代码:

 #include <iostream>
#include <math.h>
using namespace std; int gcd(int a, int b){
return b == ? a : gcd(b, a % b);
} int polya(int m, int n){
int ans = ;
for(int i = ; i < n; i++){
ans += pow(m, gcd(n, i));//第i次旋转的循环节数为gcd(n,i)
}
if(n & ){
for(int i = ; i < n; i++){
ans += pow(m, n / + );//共有n个循环节数均为n/2+1的置换
}
}else{
for(int i = ; i < n / ; i++){
ans += pow(m, n / ) + pow(m, n / + );//有两种置换,第一种循环节数均为n/2,第二种循环节数均为n/2+1
}
}
return ans;
} int main(void){
int n, m;
while(cin >> m >> n && m + n){
cout << polya(m, n) / (n << ) << endl;
}
return ;
}

poj2409(polya 定理模板)的更多相关文章

  1. [POJ1286&POJ2154&POJ2409]Polya定理

    Polya定理 L=1/|G|*(m^c(p1)+m^c(p2)+...+m^c(pk)) G为置换群大小 m为颜色数量 c(pi)表示第i个置换的循环节数 如置换(123)(45)(6)其循环节数为 ...

  2. poj 2409(polya定理模板)

    题意:给你n种颜色和m个小球,问你有多少种不同的方案! 分析:作为模板.. 代码实现: #include <iostream> #include <cstdio> #inclu ...

  3. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  4. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

  5. poj 1286 polya定理

    Necklace of Beads Description Beads of red, blue or green colors are connected together into a circu ...

  6. P4980 【模板】Polya定理

    思路 polya定理的模板题,但是还要加一些优化 题目的答案就是 \[ \frac{\sum_{i=1}^n n^{gcd(i,n)}}{n} \] 考虑上方的式子怎么求 因为\(gcd(i,n)\) ...

  7. 【poj2409】Let it Bead Polya定理

    题目描述 用 $c$ 种颜色去染 $r$ 个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $r·c\le 32$ . 题解 Polya定理 Burnside引理 ...

  8. [洛谷P4980]【模板】Polya定理

    题目大意:给一个$n$个点的环染色,有$n$中颜色,问有多少种涂色方案是的旋转后本质不同 题解:$burnside$引理:$ans=\dfrac1{|G|}\sum\limits_{g\in G}A_ ...

  9. poj2409:Let it Bead(置换群 polya定理)

    题目大意:长度为n的项链,要染m种颜色,可以通过旋转或翻转到达的状态视为同一种,问有多少种染色方案. 学了一波polya定理,发现很好理解啊,其实就是burnside定理的扩展. burnside定理 ...

随机推荐

  1. 问题:只能在执行 Render() 的过程中调用 RegisterForEventValidation;结果:只能在执行 Render() 的过程中调用 RegisterForEventValidation

    只能在执行 Render() 的过程中调用 RegisterForEventValidation 当在导出Execl或Word的时候,会发生只能在执行 Render() 的过程中调用 Register ...

  2. Eclipse: “The import java.io cannot be resolved”

    检查一下选项: 重点看jdk的绑定 43down voteaccepted Check your Eclipse preferences: Java -> Installed JREs. The ...

  3. Stun方式的P2P实现原理(转)

    转帖地址:http://www.cppblog.com/peakflys/archive/2013/01/25/197562.html   二.STUN方式的P2P实现 STUN是RFC3489规定的 ...

  4. Linux服务器在外地,如何用eclipse连接hdfs

    配置外网和内网的映射,内部所有配置全部用内网的IP 本地所有配置皆为外网地址 本地给服务器发指令全部由映射转换为内网指定IP,即可​

  5. java中用正则表达式判断中文字符串中是否含有英文或者数字

    public static boolean includingNUM(String str)throws  Exception{ Pattern p  = Pattern.compile(" ...

  6. 主机(windows)与VMware虚拟机(linux)互传文件

    网上有不少教程,比如http://bbs.kafan.cn/thread-451327-1-1.html,我仅记录我平时用的方法. 1.VMware tools:  如果有网,且Linux有桌面的,可 ...

  7. go语言的第一个helloworld

    1.新建一个hello.go文件 添加如下代码: package main  // 代码包声明语句. import "fmt" //系统包用来输出的 func main() { / ...

  8. ngx-bootstrap使用01 安装ngx-bootstrap和bootstrap及其使用、外部样式引入

    1 版本说明 2 新建一个angular项目 ng new 项目名 --stayle=scss 代码解释:创建一个样式文件格式为SCSS的angular项目 技巧01:由于我angular-cli的版 ...

  9. ngx-bootstrap使用03 Alerts组件、利用Object.assign复制对象

    1 Alerts 该组件用于给用户操作提供反馈信息或者提供一些警告信息 2 用法 2.1 下载ngx-bootstrap依赖 参考博文:点击前往 2.2 在模块级别导入AlertModule模块 技巧 ...

  10. ubuntu16配置Mask-RCNN

    一.安装Anaconda3 1.下载 下载地址:https://www.continuum.io/downloads 2.安装 在文件目录下执行:bash Anaconda3-4.2.0-Linux- ...