描述

"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.

输入

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.

输出

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.

样例输入

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

样例输出

1
2
3
5
8
13
21

代码如下:

 #include <cstdio>
#include <cmath> int gcd(int x, int y) {
return y ? gcd(y, x % y) : x;
}
int main()
{
int c,s;
while(scanf("%d %d",&c,&s)&&(c!=||s!=)){
int ans=;
for(int i=;i<=s;i++){//旋转
int xhj=gcd(s,i);//旋转的循环节
ans+=(int)pow(c*1.0,xhj*1.0);
}
if(s%==){//翻转s为奇数时
ans+=(int)(s*pow(c*1.0,(s+)/*1.0));//所有s都是
} else{//翻转s为偶数时
ans+=(int)((s/)*pow(c*1.0,(s/+)*1.0));//对称轴过顶点循环节数均为s/2+1
ans+=(int)((s/)*pow(c*1.0,s/*1.0));//对称轴不过顶点循环节数均为s/2
}
ans/=(*s);
printf("%d\n",ans);
} return ;
}

Polya定理:

Polya定理是组合数学中十分重要的定理。用一个简单粗暴的例子粗略介绍一下~

eg:用2种颜色去染排成一个圈的6枚棋子。如果通过旋转得到只算一种,问有多少种颜色状态。

置换:用矩阵形式表示的顶点的变换。

例子中,将棋子从某个点顺时针标上1~6,则将所有棋子顺时针旋转一个位置的置换可表示为:

例子中共有6个置换:

c1  (1)(2)(3)(4)(5)(6)    c2 (1 6 5 4 3 2 1)

c3  (1 5 3 1)(2 6 4)       c4 (1 4)(2 5)(3 6)

c5  (1 3 5)(2 4 6)          c6 (1 2 3 4 5 6)

即c1=6(6个循环),c2=1(1个循环),c3=2(2个循环),c4=3(3个循环),c5=2(2个循环),c6=1(1个循环)。

循环的找法(自我理解):从第二行找1(记录)。再找第一行的1对应的第二行数字(记录)。以第一行的1对应的第二行的数字为第一行的数字,找其下第二行的数字(记录)。以此类推。

以上主要有用的数据就是分别有几个循环。

再利用下面很重要很重要很重要的公式~

用m种颜色对这N个点染色,则不同的染色方案数为:

S=(mc1+mc2+...+mc|G|)/|G|

             带入公式后例题的答案:

S=(26+21+22+23+22+21)/6=14.

Polya定理在算法竞赛的应用(狠狠狠狠狠重要):

常见置换的循环数

Ø计算置换的循环数,是这一算法的瓶颈.如果能够快速计算出各置换的循环数,就可以大大提高程序的运行效率

Ø旋转:n个点顺时针(或逆时针)旋转i个位置的置换,循环数为gcd(n,i)

Ø翻转:

1.n为偶数时,

对称轴不过顶点:循环数为n/2

对称轴过顶点:循环数为n/2+1

2.n为奇数时,循环数为(n+1)/2

解题思路

题目大意:

输入:文件的每行定义了一个测试用例,并且包含两个整数:可用颜色c,接着为手镯s的长度的数目。输入由C = S= 0终止。否则,这两个都为正,并且,由于在手镯制造机技术困难,CS<= 32,即它们的产品不超过32个。

输出:有关单行每个测试用例输出独特的手镯数量。下图显示了可以与2种颜色和5珠粒制成的8个不同的手镯。

。。他喵的写到这里我才发现,好像上面的就是解题思路。本题直接套Polya定理搞定~。

百练_2409 Let it Bead(Polya定理)的更多相关文章

  1. POJ2409 Let it Bead(Polya定理)

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

  2. POJ 2409 Let it Bead (Polya定理)

    题意 用k种颜色对n个珠子构成的环上色,旋转翻转后相同的只算一种,求不等价的着色方案数. 思路 Polya定理 X是对象集合{1, 2, --, n}, 设G是X上的置换群,用M种颜色染N种对象,则不 ...

  3. 【poj2409】Let it Bead Polya定理

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

  4. POJ 2409 Let it Bead(Polya定理)

    点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...

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

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

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

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

  7. POJ 2409 Let it Bead:置换群 Polya定理

    题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...

  8. poj 2409 Let it Bead【polya定理+burnside引理】

    两种置换 旋转:有n种,分别是旋转1个2个--n个,旋转i的循环节数位gcd(i,n) 翻转:分奇偶,对于奇数个,只有一个珠子对一条边的中点,循环节数为n/2+1:对于偶数个,有珠子对珠子和边对边,循 ...

  9. HDU 3923 Invoker 【裸Polya 定理】

    参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转, ...

随机推荐

  1. handlebars模板库的资源

    web 开发中,js 解析JSON 是经常的事情.非常繁琐.handlebars 使用了模版,只要你定义一个模版,提供一个json对象,handlebars 就能吧json对象放到你定的模版中,非常方 ...

  2. JS链接页面

    window.location.href = "index.php?op=xx&extend_op=xxc" 这样是在本页打开链接 window.open("ht ...

  3. HTML5与CSS3权威指南.pdf2

    第三章 HTML5的结构 article元素更强调独立性,section元素强调分段,div元素强调css的套用,aretcle元素和section元素在核实的情况下可以调换 nav元素用作页面导航的 ...

  4. Android学习笔记1:Activity与View

    推荐一系列优秀的Android开发源码 Activity是Android应用中负责与用户交互的组件. View组件是所有UI控件.容器控件的基类,View组件就是Android应用中用户实实在在看到的 ...

  5. head frist 设计模式学习之 JVM中的博物馆奇妙夜(观察者模式)

    博物馆奇妙夜! 博物馆奇妙夜!博物馆奇妙夜!重说三!!!JVM看了<博物馆奇妙夜>电影之后,决定在自己家里开一个博物馆!毕竟需要什么new一下就好,博物馆很快就开起来了,并且任命你为馆长( ...

  6. Twitter 工程师谈 JVM 调优

    一. 调优需要关注的几个方面 内存调优 CPU 使用调优 锁竞争调优 I/O 调优 二. Twitter 最大的敌人:延迟 导致延迟的几个原因? 最大影响因素是 GC 其他的有:锁和线程调度.I/O. ...

  7. 2 weekend110的SecureCRTPortable远程连接 + 上传安装jdk + 上传安装配置hadoop

    企业公认的最新文本版本:        https://archive.apache.org/dist/ 玩玩这个远程连接软件,是个绿色软件. 别人已经做好了的. 解压之后, 下面,软件展示下, 这会 ...

  8. MAC 下安装PIL

    1. 安装使用 pip install pil 结果报如下错误 Collecting PIL Could not find a version that satisfies the requireme ...

  9. Android 系统名字、版本、API level的对应关系

    从官网上找到的,具体地址是: http://source.android.com/source/build-numbers.html Code name Version API level Lolli ...

  10. 详解Android动画之Frame Animation

    在开始实例讲解之前,先引用官方文档中的一段话: Frame动画是一系列图片按照一定的顺序展示的过程,和放电影的机制很相似,我们称为逐帧动画.Frame动画可以被定义在XML文件中,也可以完全编码实现. ...