Let it Bead
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5397   Accepted: 3609

Description

"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.

A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.

Input

Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.

Output

For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.

Sample Input

1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0

Sample Output

1
2
3
5
8
13
21 题意:每次给你m种颜色,n个珠子要成一个环,可以翻转也可以旋转,要问本质不同的染色方案有几种 首先,对于每次旋转i,循环节一定是有gcd(i,n)个,首先,如果对于一个串一直旋转i的长度,那么回到最初的时候一定是旋转了 lcm(i,n)/i 次,那么任意一个节点,一定经过了lcm(i,n)/i个节点,那么这么多个节点,都是等价类E,由于环上每个等价类的元素数量都相等,所以循环节个数为 n*i/(lcm(i,n)=gcd(i,n) 到这里为止,旋转的情况我们已经考虑过了,我们再考虑一下翻转的情况:
对于奇数,翻转情况只有一个点,和它对面的中点作为对称轴,一共n种,循环节为n/2+1 对于偶数,有两种情况,一个是两个对称点构成对称轴,n/2种,循环节为n/2+1
一个是两个中点构成对称轴,也是n/2种,循环节为n/2
综上,所有的置换总数有2*n种,这时候我们只需要利用polay计数就可以AC了 2016-06-10:PKUSC居然考了这题,TAT还好有学过。。
 #include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#define ll long long
int n,m;
int Pow(int x,int y){
int res=;
while (y){
if (y%) res*=x;
x*=x;
y/=;
}
return res;
}
int gcd(int a,int b){
if (b==) return a;
else return gcd(b,a%b);
}
int main(){
while (scanf("%d%d",&m,&n)!=EOF){
if (n==&&m==) return ;
int ans=;
for (int i=;i<n;i++)
ans+=Pow(m,gcd(i,n));
if (n%){
ans+=n*Pow(m,(n/)+);
ans/=*n;
printf("%d\n",ans);
}else{
ans+=n/*Pow(m,(n/)+);
ans+=n/*Pow(m,n/);
ans/=*n;
printf("%d\n",ans);
}
}
}
 

poj2409 Let it Bead的更多相关文章

  1. POJ2409 Let it Bead(Polya定理)

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6443   Accepted: 4315 Descr ...

  2. Burnside引理和polay计数 poj2409 Let it Bead

    题目描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ...

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

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

  4. Burnside引理与Polya定理 学习笔记

    原文链接www.cnblogs.com/zhouzhendong/p/Burnside-Polya.html 问题模型 有一个长度为 $n$ 的序列,序列中的每一个元素有 $m$ 种取值. 如果两个序 ...

  5. polay计数原理

    公式: Burnside引理: 1/|G|*(C(π1)+C(π2)+C(π3)+.....+C(πn)): C(π):指不同置换下的等价类数.例如π=(123)(3)(45)(6)(7),X={1, ...

  6. 【POJ2409】Let it Bead Pólya定理

    [POJ2409]Let it Bead 题意:用$m$种颜色去染$n$个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $n,m$很小就是了. 题解:在旋转$i ...

  7. 【poj2409】 Let it Bead

    http://poj.org/problem?id=2409 (题目链接) 题意 一个n个珠子的项链,每个珠子可以被染成t种颜色.项链可以翻转和旋转,问不同的染色方案数. Solution Pólya ...

  8. 【poj2409】Let it Bead Polya定理

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

  9. POJ 2409 Let it Bead(Polya简单应用)

    Let it Bead 大意:给你m种颜色,n个珠子串起来.旋转跟反转同样算同样,问有多少种不同的涂色组合方式. 思路:Polya的简单应用. /*************************** ...

随机推荐

  1. elasticsearch 修改内存

    [elk@zjtest7-redis bin]$ cat elasticsearch.in.sh if [ "x$ES_MIN_MEM" = "x" ]; th ...

  2. windows上安装winsshd

    winsshd下载地址:http://www.bitvise.com/ssh-server-download 安装后默认配置即可使用:

  3. NOI2011 NOI嘉年华

    http://www.lydsy.com/JudgeOnline/problem.php?id=2436 首先离散化,离散化后时间范围为[1,cnt]. 求出H[i][j],表示时间范围在[i,j]的 ...

  4. Paint House II 解答

    Question There are a row of n houses, each house can be painted with one of the k colors. The cost o ...

  5. HDU--3466(0-1背包+贪心/后效性)

    题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有  价格 P    价值 V    还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...

  6. cocos2dx-lua绑定自定义c++类(一)

    本文主要介绍mac上,如何将自定义的c++类,绑定到lua. 1.工具先行 找到 你的cocos2d-x/tools/tolua++,里面文件按类型大致分为: (1)*.pkg:用于定义要绑定的c++ ...

  7. 学习phpcms模板方法:

    1.改官方模板,读里面的代码,改改它,看看有什么变化,如果不明白,去官方论 坛.查手册.专业人士还可以看数据库.2.复制实例代码,整理笔记,到实战的时候,就直接复制,改改参数即可.

  8. 基于PCA和SVM的人脸识别

    程序中采用的数据集是ORL人脸库,该人脸库共有400副人脸图像,40人,每人10幅,大小为112*92像素,同一个人的表情,姿势有少许变化. 程序的流程主要分为三部分,数据的预处理(PCA降维和规格化 ...

  9. AngularJs学习笔记2——四大特性之MVC

    angularJs的四大特性 ①.采用MVC的设计模式 ②.双向数据绑定 ③.依赖注入 ④.模块化设计 现在细说一下MVC的设计模式: MVC: Model(模型)--项目中的数据 View(视图)- ...

  10. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...