uva 11255 Necklace
来源:互联网 发布:linux怎么启动oracle 编辑:程序博客网 时间:2024/05/22 20:57
【题目】
Once upon a time, three girls|Winnie, Grace and Bonnie|owned a large number of pearls. However,
each of them only had a single color of pearls. Winnie had white pearls, Grace had grey pearls and
Bonnie had black pearls. One day, after a long discussion, they decided to make necklaces using the
pearls. They are interested in knowing how many patterns can be formed using a certain number of
pearls of each color, and have asked you to solve this problem for them.
Note that rotating or
ipping over a necklace cannot produce a different kind of necklace. i.e. The
following gure shows three equivalent necklaces.
The following gure shows all possible necklaces formed by 3 white pearls, 2 grey pearls and 1 black
pearl.
Input
The input begins with an integer N ( 2500) which indicates the number of test cases followed. Each
of the following test cases consists of three non-negative integers a, b, c, where 3 a + b + c 40.
Output
For each test case, print out the number of different necklaces that formed by a white pearls, b grey
pearls and c black pearls in a single line.
Sample Input
2
3 2 1
2 2 2
Sample Output
6
11
【分析】
运用组合数学的知识,根据a+b+c的奇偶性大力讨论。
【代码】
//UVA 11255 Necklace#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define N 40#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(i=j;i<=k;i++)using namespace std;const int mxn=45;int n,a,b,c;int C[mxn][mxn];inline int gcd(int x,int y) {return x%y==0?y:gcd(y,x%y);} int main(){ int i,j,T; fo(i,0,N) C[i][0]=1; fo(i,1,N) fo(j,1,i) C[i][j]=C[i-1][j-1]+C[i-1][j]; scanf("%d",&T); while(T--) { ll ans=0; scanf("%d%d%d",&a,&b,&c); n=a+b+c; fo(i,1,n) { int x=n/gcd(n,i); //循环节大小 if(a%x==0 && b%x==0 && c%x==0) ans+=C[n/x][a/x]*C[n/x-a/x][b/x]; } if((n&1) && (a&1)+(b&1)+(c&1)==1) ans+=C[n/2][a/2]*C[n/2-a/2][b/2]; if(!(n&1)) { if((a&1)+(b&1)+(c&1)==0) ans+=C[n/2][a/2]*C[n/2-a/2][b/2]*n; else if((a&1)+(b&1)+(c&1)==2) ans+=C[n/2-1][a/2]*C[n/2-1-a/2][b/2]*n; } printf("%lld\n",ans/n/2); } return 0;}
- UVA 11255 Necklace(Polya)
- UVA 11255 - Necklace(Ploya)
- uva 11255 - Necklace(置换)
- uva 11255 Necklace
- uva 11255 Necklace (polya)
- uva 11255 Necklace
- Necklace UVA
- Necklace UVA
- UVA 11255 - Necklace (等价置换)
- uva 10054 - The Necklace
- uva 10054 - The Necklace
- UVa 10054 - The Necklace
- UVA 10054 The Necklace
- Uva-10054-The Necklace
- uva 10054 - The Necklace
- uva 10054 - The Necklace
- uva 10054 - The Necklace
- UVA 10054 The Necklace
- vggnet笔记(Very Deep Convolutional Networks for Large-Scale Image Recognition)
- 微信开发之上传素材
- 搜索二叉树含迭代器
- java项目部署到linux系统上出现java.lang.OutOfMemoryError: PermGen space错误
- java的图片上传详解
- uva 11255 Necklace
- 死锁及避免死锁的银行家算法
- Nginx配置Tomcat集群服务器的负载均衡
- GDOI2016酱油记(以前的文章补发)
- 二叉树的层次遍历、哈夫曼树及哈夫曼编码的建立
- php实现「浏览记录」按日期分组
- 绝对路径${pageContext.request.contextPath}用法及其与web.xml中Servlet的url-pattern匹配过程
- 2654: tree
- Spark RDD API 参考示例(四)