[ZOJ1961]Let it Bead
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 cdistinct 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 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
polya置换的裸题了,考虑旋转,我们枚举所有可能的旋转方式,所以得到的循环节个数为gcd(i,n),因此答案为\(\sum\limits_{i=1}^{n} c^{gcd(n,i)}\)
再考虑一下翻转,我们分奇数和偶数进行讨论,如果是奇数,那么不论如何找对称轴,都必定会形成\(\frac{n}{2}+1\)个循环节,再乘上\(n\)即可;如果是偶数,那么就会有\(\frac{n}{2}\)和\(\frac{n-2}{2}+2\)两种循环节情况,然后每种情况各占\(\frac{n}{2}\)条对称轴
最后把答案除一下置换总数\(2*n\)即可
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int mlt(int a,int b){
int res=1;
for (;b;b>>=1,a=a*a) if (b&1) res=res*a;
return res;
}
int main(){
while (true){
int m=read(),n=read(),ans=0;
if (!n&&!m) break;
for (int i=1;i<=n;i++) ans+=mlt(m,gcd(n,i));
if (n&1) ans+=n*mlt(m,n/2+1);
else ans+=(mlt(m,n/2+1)+mlt(m,n/2))*(n>>1);
printf("%d\n",ans/(2*n));
}
return 0;
}
[ZOJ1961]Let it Bead的更多相关文章
- 百练_2409 Let it Bead(Polya定理)
描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ca ...
- poj 2049 Let it Bead(polya模板)
Description Cannery Row percent of the target audience insists that the bracelets be unique. (Just ...
- poj2409 Let it Bead
Let it Bead Time Limit: 1000MS M ...
- POJ1975 Median Weight Bead floyd传递闭包
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- 【POJ2409】Let it Bead Pólya定理
[POJ2409]Let it Bead 题意:用$m$种颜色去染$n$个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $n,m$很小就是了. 题解:在旋转$i ...
- POJ-1975 Median Weight Bead(Floyed)
Median Weight Bead Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3162 Accepted: 1630 De ...
- 珍珠 Median Weight Bead 977
描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...
- Median Weight Bead(最短路—floyed传递闭包)
Description There are N beads which of the same shape and size, but with different weights. N is an ...
随机推荐
- Eclipse中Maven运行项目时在Console中无日志出现的问题解决
这是由于工作空间损坏造成的,比如重装JDK后,或者重装Maven后这些问题.解决方法如下: 1.删除现有工作空间,重新选择一个新的. 2.重置Workspece. 3.可能是Maven版本太新导致的, ...
- [正在学习开发板]分享--- iTOP-4412移植CAN
首先拷贝迅为提供的 libcanjni.tar.gz 压缩包到 android 源代码的"iTop4412_ICS/device/samsung/common"文件夹以下,然后使用 ...
- Android Activity与远程Service的通信学习总结
当一个Service在androidManifest中被声明为 process=":remote", 或者是还有一个应用程序中的Service时,即为远程Service, 远程的意 ...
- MySQL基础笔记(六) 存储过程与函数
写在开头:本文所有的示例都是基于workers表,表中保存了某公司的员工姓名.性别.工资.年龄和居住城市,如下: +----+-----------+--------+--------+------+ ...
- Android网络通信之Socket
在移动APP开发中.网络通信数据传输是必定存在的.移动APP离开了网络通信数据传输的功能方式,就好比一潭死水,永远都 是原来的样子. 提到网络通信传输数据.首先出如今程序猿脑海中的是HTTP协议传输, ...
- Jenkins系列之-—04 配置用户和权限控制
一.安装插件 插件名称:Role-based Authorization Strategy Role Strategy Plugin插件可以对构建的项目进行授权管理,让不同的用户管理不同的项目. 二. ...
- iOS视频流开发(2) — 视频播放
iOS视频流开发(2) — 视频播放 承上篇,本篇文章主要介绍iOS视频播放需要用到的类.以及他们的使用场景和开发中遇到的问题. MPMoviePlayerViewController MP简介 i ...
- How to get service execuable path
Some time we need to get specific service path and then do something you want. there are 2 way to ge ...
- C# MVC 枚举转 SelectListItem
<span style="font-size: 18px; font-family: Arial, Helvetica, sans-serif; background-color: r ...
- iOS7获取UUID以及转换MD5
近期项目开发,运用到要获取UUID转MD5,可是iOS7不能使用获取的UDID的接口(涉及到隐私),获取MAC地址的方式的接口在iOS7下也废弃了.眼下可能的就是获取UUID了,可是在iOS7下,UU ...