组合数学之Polya计数 TOJ1116 Let it Bead
1116: Let it Bead 
Total Submit: 7 Accepted:4
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
经典题目
#include<stdio.h>
#include<string.h>
int eular(int n)
{
int ret=,i;
for(i=; i*i<=n; i++)
{
if(n%i==)
{
ret*=i-;
n/=i;
while(n%i==)
{
n=n/i;
ret*=i;
}
}
if(n==)
break;
}
if(n>)
ret*=n-;
return ret;
}
int po(int a,int b)
{
int ret=,i;
for(i=; i<=b; i++)
ret*=a;
return ret;
}
int main()
{
int n,ans,i,m;
while(~scanf("%d%d",&m,&n))
{
if(!n&&!m)break;
ans=;
for(i=; i*i<n; i++)
{
if(n%i==)
{
ans+=eular(n/i)*po(m,i);
ans+=eular(i)*po(m,n/i);
}
}
if(i*i==n)
ans+=eular(n/i)*po(m,i);
if(n&)
ans+=po(m,n/+)*n;
else
ans+=po(m,n/)*n/+po(m,n/+)*n/;
printf("%d\n",ans/n/);
}
return ;
}
也是很优秀的写法
#include<bits/stdc++.h>
using namespace std;
int c,n,ans;
int po(int p,int n)
{
int ans=;
while(n)
{
if(n&)ans*=p;
p*=p,n>>=;
}
return ans;
} int main()
{
while(cin>>c>>n&&(c||n))
{
ans=;
for(int i=; i<=n; i++)
ans+=po(c,__gcd(n,i));
if(n&)
ans+=n*po(c,n/+);
else
ans+=(po(c,n/+)+po(c,n/))*(n/);
cout<<ans//n<<endl;
}
return ;
}
组合数学之Polya计数 TOJ1116 Let it Bead的更多相关文章
- 《程序设计中的组合数学》——polya计数
我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...
- 组合数学及其应用——polya计数
在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Polya计数
Let it Bead Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5365 Accepted: 3585 Descr ...
- hdu 5868:Different Circle Permutation 【Polya计数】
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)
Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 群论&Polya计数
群论&Polya计数 其实在我听课的过程中,我发现针对于学习OI中的群并没有什么过多必要向内学习... 群 以后会补的. 就是\(QQ\)群. 置换 置换就是一个... \[ \begin{m ...
- 组合数学之Pólya计数理论
1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...
随机推荐
- 科学效法自然:微软研究人员测试AI控制的滑翔机
编者按:正如一颗苹果砸出了万有引力,自然界所有存在的事物和现象都有其科学合理的一面,小小的鸟儿也能够给科学带来丰富的灵感和启示. 最近,微软研究人员从自然出发,研究鸟类能够自由停留在空中的科学原理,并 ...
- GPnP profile内容
<?xml version="1.0" encoding="UTF-8"?> <gpnp:GPnP-Profile Version=&quo ...
- 面试题-谈谈你对Java平台的理解
平台无关性 GC 语言特性 面向对象 类库 异常处理 一次编译到处运行 JVM如何加载Class文件 Java反射 ClassLoader 种类 双亲委派机制 loadcalss和forName
- graphviz 绘制架构图
架构图: 1.依赖调用关系.(类似文献引用关系, graphviz 自动将每一次调用升一次层级) 2.依赖调用可能是上下层级调用,也可能是同层级引用. 需人工去梳理出这些关系 3. 引用多的用颜色标识 ...
- linux文件或文件夹常见操作
创建文件夹 mkdir [-p] DirName 在工作目录下,建立一个名为 A 新的子目录 : mkdir A 在工作目录下的 B目录中,建立一个名为 T 的子目录: 若 B 目录不存在, ...
- Oracle11g 数据库的导入导出
导出: 全部: exp imagesys/imagesys@orcl file=/icms/20170116.dmp full=y 用户: exp imagesys/imagesys @orcl fi ...
- 【转】BP神经网络
学习是神经网络一种最重要也最令人注目的特点.在神经网络的发展进程中,学习算法的研究有着十分重要的地位.目前,人们所提出的神经网络模型都是和学习算 法相应的.所以,有时人们并不去祈求对模型和算法进行严格 ...
- 封装一个优雅的element ui表格组件
现在做后台系统用vue + elementUI 的越来越多,那element ui的 el-table 组件肯定也离不开.虽然element ui的table组件很好.但是表格和分页是分离的.每次写表 ...
- STA basic
- laravel5 使用try catch
在laravel5中使用以下代码并没有捕获异常 try{ var_dump($val); }catch (Exception $e){ var_dump($e); } Laravel 5 时代控制器 ...