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. 安卓,通过本地应用分享到微信、facebook等

    别的不说了,直接上代码. 支持分享到微信.微博.facebook.twitter package com.example.shareSample; import java.util.List; imp ...

  2. Address Book(地址薄)

    <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.Scene?> ...

  3. spring加载properties配置文件

    public static void main(String[] args){    String path="E:/workspace/bocMarketData/src/config/P ...

  4. Xcode7中你一定要知道的炸裂调试神技(转)

    1.Address Sanitizer: 妈妈再也不用担心 EXC_BAD_ACCESS? EXC_BAD_ACCESS一直是很多开发者的噩梦,因为这个错误很不直观,出现后往往要花很长时间才能定位到错 ...

  5. 关于bootstrap--表格(tr的各种样式)

    只需要<tr class="active">就可以用active样式. 特别提示:除了”.active”之外,其他四个类名和”.table-hover”配合使用时,Bo ...

  6. Object-c学习之路十二(OC的copy)

    oc中的拷贝分为:copy(浅拷贝)和mutablecopy(深拷贝). 浅拷贝也为指针拷贝,拷贝后原来的对象计数器会+1: 深拷贝为对象拷贝,原来的对象计数器不变. 注意:自定义对象拷贝时要实现NS ...

  7. 仿糯米弹框效果demo

    代码例如以下: <!doctype html> <html lang="en"> <head> <meta charset="U ...

  8. Live555 实战之框架简单介绍

    作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 上一篇文章简要介绍了怎样以共享库的方式交叉编译Live555,今天再来介绍live源代码框架. 先 ...

  9. LRU Cache的简单c++实现

    什么是 LRU LRU Cache是一个Cache的置换算法,含义是“最近最少使用”,把满足“最近最少使用”的数据从Cache中剔除出去,并且保证Cache中第一个数据是最近刚刚访问的,因为这样的数据 ...

  10. 学习selenium所须要具备的技术

    学习selenium所须要具备的知识或技术 1.selenium进行的自己主动化測试是基于ui层面的,所以html,css,javascript基本上是不可缺少的,至于javascript,有非常多的 ...