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. 自制单片机之七……RS232串口

    在我的板子上其它的部分都已完成了,现在就剩下RS232串口了.串口对于单片机很重要,有了它就可以和PC通信了,可以用PC来控制你的单片机,也可以将你单片机上采集的数据传到PC上. 留的位置好像有点挤. ...

  2. Handler处理长时间事件

    当我们在处理一些比较长时间的事件时候,比如读取网络或者数据库的数据时候,就要用到Handler,有时候为了不影响用户操作应用的流畅还要开多一个线程来区别UI线程,在新的线程里面处理长时间的操作.开发的 ...

  3. Linux企业级项目实践之网络爬虫(7)——DNS解析

    DNS 是Domain Name Service的缩写.域名系统为Internet上的主机分配域名地址和IP地址.IP地址不易于记忆,然而域名地址相比较而言是方便于记忆的.用户如果使用域名地址,当想获 ...

  4. c# splitter控件使用简介

    摘自:http://blog.itpub.net/26221264/viewspace-735903 1.先在窗体上放置部分一的控件,这里是TreeView控件,然后把它的 Dock 属性设置为 Le ...

  5. Python partial函数

    以前都是摘录的其他网友的博客,很少是自己写的,学习阶段,多多学习.今天开始自己写了,首先写一下刚刚遇到的partial函数. 1.partial函数主要是对参数的改变,假如一个函数有两个参数,而其中一 ...

  6. MergeSort 归并排序

    实现: 二路归并 public class TestMergeSort { public int[] mergeSortArray(int[] arr, int left, int right){ i ...

  7. poj 3176 Cow Bowling(dp基础)

    Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...

  8. qt动态更新界面的菜鸟代码,请指出

    qt简单界面更新代码(菜鸟级)(部分代码) self.timers_1=QtCore.QTimer(self) self.timers_1.timeout.connect(self.min_1) se ...

  9. (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...

  10. Hive MapJoin

    摘要 MapJoin是Hive的一种优化操作,其适用于小表JOIN大表的场景,由于表的JOIN操作是在Map端且在内存进行的,所以其并不需要启动Reduce任务也就不需要经过shuffle阶段,从而能 ...