[ACM] POJ 2409 Let it Bead (Polya计数)
参考:https://blog.csdn.net/sr_19930829/article/details/38108871
#include <iostream>
#include <string.h>
using namespace std;
int c,n;//c种颜色,n个珠子
int ans; int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
} int power(int p,int n)//快速幂求公式里的k的nc(g)次方
{
int ans=;
while(n)
{
if(n&)
ans*=p;
p*=p;
n/=;
}
return ans;
} int main()
{
while(cin>>c>>n&&(c||n))
{
ans=;
for(int i=;i<=n;i++)
ans+=power(c,gcd(n,i));//相当于求图3-1中左边的循环群染色数
if(n&)//是奇数,有n个包含(n/2+1)个循环节的循环群
ans+=n*power(c,n/+);
else
ans+=(power(c,n/+)+power(c,n/))*(n/);
ans/=*n;//别忘了除以置换群的总个数
cout<<ans<<endl;
}
return ;
}
[ACM] POJ 2409 Let it Bead (Polya计数)的更多相关文章
- poj 2409 Let it Bead Polya计数
旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文 ...
- POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...
- POJ 2409 Let it Bead (Polya定理)
题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...
- POJ 2409 Let it Bead:置换群 Polya定理
题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...
随机推荐
- February 26 2017 Week 9 Sunday
There is only one happiness in life, to love and be loved. 生命中只有一种幸福,爱与被爱. Some one told me that hea ...
- 【图文详解】Zookeeper集群搭建(CentOs6.3)
Zookeeper简介: Zookeeper是一个分布式协调服务,就是为用户的分布式应用程序提供协调服务的. A.zookeeper是为别的分布式程序服务的 B.Zookeeper本身就是一个分布式程 ...
- MySQL:数据库入门篇4
1. 视图 创建视图 create view 视图名字 as 查询sql语句; drop view 视图名字; alter view 视图名字 as 查询sql语句; 2. 触发器 1. 插入事件触发 ...
- Python-利用flask模块创建web接口
一.创建一个实现登录的接口 import flask from flask import request #获取参数 # import json #post请求传入json对象时,通过json获取参数 ...
- 【luogu P1111 公路修建】 题解
题目链接:https://www.luogu.org/problemnew/show/P1111 考察并查集,运用kruskal的思想很好做.注意几个小问题即可. #include<iostre ...
- c++ 虚基类应用
多重继承存在二义性,为了消除二义性在访问相同名称的属性时需要加上类名,加以区分.虽然这样可以解决二义性,但是相同的属性出现在多个基类中,为了解决数据冗余,c++引入了虚基类. 虚基类定义:class ...
- webapi是如何绑定参数的(How WebAPI does Parameter Binding)
原文地址 由于工作原因,要使用ASP.NET WEBAPI(非mvc webapi),前几天时间一直很紧张,所以webapi一直将就用,今天下午好不容易有时间终于看了下,解决了自己一直疑惑的问题,在此 ...
- caffe convert mxnet
https://github.com/apache/incubator-mxnet/tree/430ea7bfbbda67d993996d81c7fd44d3a20ef846/tools/caffe_ ...
- Spring知识点总结(四)之SpringAOP基础
1. Spring aop中的基本概念 • 连接点(Joinpoint):在程序执行过程中某个特定的点,比如某方法调用的时候或者处理异常的时候.在Spring AOP中,一个连接 ...
- [Oracle]分区索引
上一节学习了分区表,接着学习分区索引. (一)什么时候对索引进行分区 · 为了避免移动数据时重建整个索引,可对索引分区,在重建索引时,只需重建与数据分区相关的索引: · 在对分区表进行维护时,为了避免 ...