描述

"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. DATE_FORMAT()(转)

    mysql中DATE_FORMAT(date, format)函数可根据format字符串格式化日期或日期和时间值date,返回结果串. 也可用DATE_FORMAT( ) 来格式化DATE 或DAT ...

  2. hdoj 2074 叠筐

    叠筐 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  3. Verilog HDL模块的结构

    一个设计是由一个个模块(module)构成的.一个模块的设计如下: 1.模块内容是嵌在module 和endmodule两个语句之间.每个模块实现特定的功能,模块可进行层次的嵌套,因此可以将大型的数字 ...

  4. 使用GitHub管理源代码

    作为一个开发员,源码的管理是一个头等大事来的,想象一下,修改完成却发现文件丢失了,该怎么办?有了源代码管理工具,能够帮助我们查看某个代码文件的修改内存及历史修改记录. 作为.Net开发员,我使用过VS ...

  5. Apache Commons 工具类

    http://blog.csdn.net/feicongcong/article/details/53374399http://blog.csdn.net/hsienhua/article/detai ...

  6. 界面编程模仿篇(QQ登录界面逼真篇)

    写了好多天的爬虫,偷空前前后后用了两天的时间(排除吃饭睡觉)写完了这个QQ登录界面,看起来还凑和着吧,如果是的大神的,莫见笑,纯属业余作品,废话先不多说,截图如下,其中第二幅图片中的红色方框部份有待完 ...

  7. Navicat远程连接MySQL数据库

    1.打开Navicat,在界面的“主机名和IP地址”处输入IP地址,一般是192.168.1.1 2.输入相应的用户名和密码,点击连接测试,确认是否已经连接,之后就可以点击确定了 3.找到相应的数据库 ...

  8. Excel异常Cannot get a text value from a numeric cell

    POI操作Excel时数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric ...

  9. STL algorithm算法merge(34)

    merge原型: std::merge default (1) template <class InputIterator1, class InputIterator2, class Outpu ...

  10. bash if 表达式

    .bash把[[ $a -lt $b ]]看作一个单独的元素,并且返回一个退出码.退出码0为真,非零为假 例如: a= b=c [[ $a -lt $b ]] echo $? # a小于b为真 [[ ...