【POJ 2409】 Let it Bead(置换、burnside引理)

Let it Bead

"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


  要考虑旋转和翻转。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<cmath>
 7 using namespace std;
 8 #define Maxn 60
 9 #define LL long long
10
11 LL pw[110];
12
13 int gcd(int a,int b)
14 {
15     if(b==0) return a;
16     return gcd(b,a%b);
17 }
18
19 int main()
20 {
21     int n,t;
22     while(1)
23     {
24         scanf("%d%d",&t,&n);
25         if(n==0&&t==0) break;
26         pw[0]=1;
27         for(int i=1;i<=n;i++) pw[i]=pw[i-1]*t;
28         LL a=0;
29         for(int i=0;i<n;i++) a+=pw[gcd(i,n)];
30         LL b=0;
31         if(n%2==1) b=n*pw[(n+1)/2];
32         else b=n/2*(pw[n/2+1]+pw[n/2]);
33         printf("%lld\n",(a+b)/2/n);
34     }
35     return 0;
36 }

2017-01-13 11:43:09

时间: 2024-11-04 22:22:55

【POJ 2409】 Let it Bead(置换、burnside引理)的相关文章

NYOJ 280 LK的项链 &amp;&amp;POJ 2409 Let it Bead(polya 定理)

NYOJ 280 LK的项链  :click here POJ 2409 Let it Bead:click here 题意:一盒有红.蓝.绿三种颜色的珠子,每种颜色珠子的个数都大于24,现在LK想用这一盒珠子穿出一条项链,项链上的珠子个数为n(0<=n<=24),请你帮她计算一下一共可以用这一盒珠子可以穿出多少条不同的项链.通过旋转.翻转达到同一种状态的被认为是相同的项链. poj 上是c种颜色,s个珠子组成,数据比24小. 思路:今天刚接触到polya 定理: Polya定理:设G是n个对

poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子,要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后相同的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya到底是什么东东,它主要计算全部互异的组合的个数.对置换群还是似懂略懂.用polya定理解决问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这种不同颜色的珠子构成项链的问题可以把N个珠子看成正N边形. Polya定理:(1)设G是p个对象

POJ 2409 Let it Bead

这个题和POJ 1286 是一个题,只不过那是一个颜色数量固定的题而这个不固定. 这是链接:POJ 1286 Necklace of Beads   下面是代码: #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #

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

Let it Bead 大意:给你m种颜色,n个珠子串起来,旋转跟反转相同算相同,问有多少种不同的涂色组合方式. 思路:Polya的简单应用. 1 /************************************************************************* 2 > File Name: POJ2409.cpp 3 > Author: GLSilence 4 > Created Time: 2014年07月29日 星期二 22时56分58秒 5 **

[ACM] POJ 2409 Let it Bead (Polya计数)

Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4434   Accepted: 2916 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 b

poj 1286 Necklace of Beads &amp;amp; poj 2409 Let it Bead(初涉polya定理)

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya究竟是什么东东.它主要计算所有互异的组合的个数.对置换群还是似懂略懂.用polya定理解决这个问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这样的不同颜色的珠子构成项链的问题能够把N个珠子看成正N边形. Polya定理:(1)设G是p

BZOJ_[HNOI2008]_Cards_(置换+Burnside引理+乘法逆元+费马小定理+快速幂)

描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1004 共n个卡片,染成r,b,g三种颜色,每种颜色的个数有规定.给出一些置换,可以由置换得到的染色方案视为等价的,求等价类计数. 分析 给出置换求等价类计数,用Burnside引理:等价类计数=(每一个置换不动点的和)/置换数.(不知道的建议去看白书) 其中不动点是指一个染色方案经过置换以后染色与之前完全相同. 1.求不动点个数. 不动点的话同一个循环内的每一个点的颜色必须相同(否则不同颜色

POJ 2409 Let it Bead [置换群 Polya]

传送门 题意:$m$种颜色$n$颗珠子,定义旋转和翻转两种置换,求不等价着色数 暴力求每个置换的循环节也许会$T?$ 我们可以发现一些规律: 翻转: $n$为奇数时每个置换有$1+\frac{n-1}{2}$个循环 $n$为偶数时穿过点的对称有$\frac{n}{2}$个循环,穿过边的有$\frac{n}{2}+1$个循环 旋转: 旋转$i$次的置换的循环个数为$gcd(n,i)$ 可以这样想,从一个点开始每次走$i$步最后走到原位的最少步数$a$就是一个循环的长度 $ ai \equiv \p

poj 2409 Let it Bead Polya计数

旋转能够分为n种置换,相应的循环个数各自是gcd(n,i),个i=0时不动,有n个 翻转分为奇偶讨论,奇数时有n种置换,每种有n/2+1个 偶数时有n种置换,一半是n/2+1个,一半是n/2个 啃论文,PPT,各种书好久才看懂Polya定理,近期做数学题做的严重怀疑自己的智商. #include <iostream> #include <cstdio> #include <cstdlib> #include<algorithm> #include<ma

POJ 2409 Let it Bead P&#243;lya定理

题目大意:给定一个n个点的环,可以旋转和翻转,要求涂上c种不同的颜色,问等价类数目 首先我们不考虑翻转 假设一次旋转k个位置 那么循环个数显然是Gcd(n,i) 现在考虑翻转 易知所有的置换都可以由[沿着某个固定的对称轴翻转]和[旋转]两步组成 观察一个环 比如我们将对称轴设定为1号节点与圆心的连线 一次旋转k个位置 那么每次置换x会被换到((n+2)-x+k-1)%n+1的位置 我们会发现置换两次之后x就回到了原位 乍一看每个置换都是(AB)(CD)(EF)这样的形式 但是我们忽视了可能一个点