描述

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

    2014-08-31 Boost库是一个经过千锤百炼.可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一.Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成 ...

  2. 解决Scrapy抓取中文结果保存为文件时的编码问题

    import json import codecs # Define your item pipelines here # # Don't forget to add your pipeline to ...

  3. [LeetCode] Minimum Size Subarray Sum 解题思路

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  4. 8-11-Exercise

    链接:第四次小练 A.POJ 3094   Quicksum 水题中的水题啊~ 直接上代码: #include <iostream> #include <cstdio> #in ...

  5. btrace 笔记

    转载请注明原链接地址 http://www.cnblogs.com/dongxiao-yang/p/6134393.html btrace 是一个可以不用重启线上java业务查问题的神器,记一下自己折 ...

  6. Hibernate学习之表一对多,多对一关系

    代码: person类: public class Person { private long id; private String name; private int age; private Da ...

  7. 数据库:JDBC编程

    JDBC(Java Data Base Connectivity,java数据库连接)是一种用于运行SQL语句的Java API.能够为多种关系数据库提供统一訪问.它由一组用Java语言编写的类和接口 ...

  8. Apache Solr配置

    Solr配置 Solr的主要功能是全文检索,该功能分为两个过程:创建索引和对索引进行搜索: 在创建索引之前,需要重点关注两个配置文件:SOLR_HOME/collection1/conf/schema ...

  9. jQuery--对话框插件--dialog

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. KDB调试内核

    http://www.ibm.com/developerworks/cn/linux/l-kdbug/