[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 ...
随机推荐
- iterm2退出时保存会话状态,下次打开恢复
可以保存已经打开的窗口,本机进入的目录 无法保存ssh连接状态,无法保存ipython状态等 设置方法: 1.这里设置为yes,据说,反复修改一次,重启才起作用,实在有问题就试试 2.这里设置一下 3 ...
- 分析PMT changed for the ROM:it must be downloaded.升级失败。
应用场景描写叙述: 同样项目不同版本号(不同分支),使用Smart Phone Flash Tool工具交叉升级,出现PMT changed for the ROM;it must be downlo ...
- 火狐浏览器Firefox 如何下载网页的SWF视频,硅谷动力的网站视频怎么下载
1 使用火狐浏览器查看到底视频在哪里,我随便开了一段视频,发现这个SWF(外框套了一个Control.swf,内层才是真实的09-class.swf) 2 我们从下面这一段代码中进行分析 < ...
- 【甘道夫】并行化频繁模式挖掘算法FP Growth及其在Mahout下的命令使用
今天调研了并行化频繁模式挖掘算法PFP Growth及其在Mahout下的命令使用,简单记录下试验结果,供以后查阅: 环境:Jdk1.7 + Hadoop2.2.0单机伪集群 + Mahout0.6 ...
- Cookie防伪造防修改 电商课题:cookie防篡改
主要防止非法用户修改cookie信息,以及cookie的超时时间 传统cookie存储,Cookie(name, value),value很容易就被篡改. 防修改cookie存储,Cookie(nam ...
- MVC+ZTree大数据异步树加载
实例部分: 首先是为ZTree提供的数据规范,定义一个标准的接口,这样对于前台调用是清楚的,简单的,因为它返回的JSON数据将与ZTree默认的数据元素保持一致 /// <summary> ...
- ORA-09817
连接数据库的时候报:ORA-09817:write to audit file,在网上搜索了下,发现时oracle安装目录下面的磁盘空间不够,有不少人给出了解决办法,下面即是一例: 连接oracle ...
- MYSQL之数据库初窥
mysql数据库 1.数据库简单介绍 数据库概念:是依照数据结构来组织.存储和管理数据的仓库. 2.经常使用术语 数据库:是一些关联表的集合 数据表:表是数据的矩阵,在数据库中看起来 ...
- commons-fileupload、smartUpload和commons-net-ftp
1.本地上传 在许多Web站点应用中都需要为用户提供通过浏览器上传文档资料的功能,例如,上传个人相片.共享资料等.在DRP中,就有这个一个功能,需要将对应的物料图片上传并显示.对于上传功能,其实在浏览 ...
- 设计模式-(18)命令模式 (swift版)
一,概念: 在软件系统中,“行为请求者”与“行为实现者”通常呈现一种“紧耦合”.但在某些场合,比如要对行为进行“记录.撤销/重做.事务”等处理,这种无法抵御变化的紧耦合是不合适的.在这种情况下,如何将 ...