博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2409 Let it Bead(置换)
阅读量:4959 次
发布时间:2019-06-12

本文共 2579 字,大约阅读时间需要 8 分钟。

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

分析:

这是一道等价类计数的问题
回忆一下Burnside引理:
等价类数目等于所有置换不动点的平均数

本题有两种置换:

旋转和翻转
为了方便思考,我们把珠子按逆时针从0到n-1编上号

  • 旋转

    我们定义所有旋转都是逆时针的,这样每转动i个珠子

    0,i,2i,3i….就构成一个轮换
    这个轮换的元素个数是n/gcd(i,n)
    因此针对“转动i个珠子”这个置换
    可以看做是gcd(i,n)个轮换的乘积(每个轮换的元素个数都是n/gcd(i,n),置换中的元素个数是n,轮换的个数就很好算了)
    一共有n-1个置换
    这些置换的不动点总数为这里写图片描述

  • 翻转

    需要分两种情况讨论

    1.n为奇数
    对称轴有n条(n个置换),每一条都穿过一个珠子,形成1个单元素轮换和(n-1)/2个双元素轮换,
    一共有(n+1)/2个轮换
    这些置换的不动点总数为这里写图片描述
    2.n为偶数
    对称轴有两种,
    一种是不穿过任何珠子的对称轴,有n/2条,形成n/2个双元素轮换
    另一种是穿过两个珠子的对称轴,有n/2条,形成(n/2-1)个双元素轮换和两个单元素轮换,一共(n/2+1)个轮换,
    这些置换(共n个)的不动点总数为这里写图片描述

最后答案为

(a+b)/2n

tip

在计算旋转置换的时候

gcd是从0开始计算的
(毕竟不旋转也是一种置换,
那为什么没有“不翻转”这种置换呢,
因为“不翻转”和“不旋转”得到的置换一样,而我们的原则就是不重不漏

//这里写代码片#include
#include
#define ll long longusing namespace std;ll pow[40];int n,m;int gcd(int a,int b){ int r=a%b; while (r) { a=b;b=r; r=a%b; } return b;}int main(){ scanf("%d%d",&m,&n); while (n&&m) { pow[0]=1; for (int i=1;i<=n;i++) pow[i]=pow[i-1]*m; ll a=0; for (int i=0;i

转载于:https://www.cnblogs.com/wutongtong3117/p/7673062.html

你可能感兴趣的文章
[分组背包]ACboy needs your help
查看>>
<Android>日期,时间选择对话框
查看>>
MyBatis全局配置文件MyBatis-config.xml代码
查看>>
jquery tab插件精简版
查看>>
linux简单命令3
查看>>
.NET 3.5
查看>>
CV基础(1):计算机视觉概述
查看>>
3、生成证书请求文件
查看>>
Monkeyrunner 常用按键
查看>>
Linux 定时任务 crontab
查看>>
Harbor高可用
查看>>
poj3276
查看>>
1040. Longest Symmetric String (25)
查看>>
ubuntu root用户 phpstorm软件不能使用中文输入法
查看>>
项目管理的五大过程组及十大知识领域
查看>>
AJAX 请求中多出了一次 OPTIONS 请求 导致 Laravel 中间件无法对 Header 传入的 Token 无法获取...
查看>>
Autofs
查看>>
数据结构——数组
查看>>
MyBatis 使用枚举或其他对象
查看>>
java的小数比较反例
查看>>