UVA 11255 - Necklace (等价置换)
来源:互联网 发布:女士牛仔裤品牌 知乎 编辑:程序博客网 时间:2024/05/02 00:00
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 flipping over a necklace cannot produce a different kind of necklace. i.e. The following figure shows three equivalent necklaces.
The following figure 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
3 2 1
2 2 2
Sample output
6
11
11
Problem setter: Cho
Special thanks: Michael (for making up the story)
Source: Tsinghua-HKUST Programming Contest 2007
题意:有一个项链要染上三种颜色,每种颜色的数量分别是a,b,c, 其中通过旋转和翻转得到的情况算为一种,问一共有多少种染色情况。
思路:可以直接用Burnside定理求。 训练指南上面似乎也有类似的讲解。。。所以就不多讲了。注意置换里面有(1,2,3,...n)这个置换,别漏了。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#include <queue>#include <set>using namespace std;#define eps 1e-8#define rep(i,a,b) for(int i = (a); i < (b); ++i)#define rrep(i,b,a) for(int i = (b); i >= (a); --i)#define clr(a,x) memset(a,(x),sizeof(a))#define mp make_pair#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define ll long long#define ld long doubleconst int maxn = 42;ll C[maxn][maxn];int dp[maxn][maxn][maxn];int a,b,c,n;void pre_init(){ rep(i,0,maxn) { C[i][0] = 1; rep(j,1,i+1) C[i][j] = C[i-1][j] + C[i-1][j-1]; }}void solve(){ int fenmu = n * 2; ll fenzi = 0; //1 2 3 .... n fenzi += C[n][a] * C[n-a][b]; //旋转 rep(d,1,n) { int len = n / __gcd(d,n); int num = n / len; if (a % len || b % len || c % len) continue; fenzi += C[num][a / len] * C[num - a / len][b / len]; } //翻转 if (n % 2) { int num = (n - 1) >> 1; int cnt = a % 2 + b % 2 + c % 2; if (cnt == 1) { fenzi += C[num][a/2] * C[num-a/2][b/2] * n; } } else { int num = n >> 1; int cnt = a % 2 + b % 2 + c % 2; if (cnt == 0) fenzi += C[num][a/2] * C[num-a/2][b/2] * (n / 2); --num; if (cnt == 2) fenzi += 2 * C[num][a / 2] * C[num - a/2][b/2] * (n / 2); else if (cnt == 0) { if (a >= 2) fenzi += C[num][(a - 2)/2] * C[num - (a - 2) / 2][b / 2] * (n / 2); if (b >= 2) fenzi += C[num][(b - 2) / 2] * C[num - (b-2) / 2][a / 2] * (n / 2); if (c >= 2) fenzi += C[num][(c - 2) / 2] * C[num - (c - 2) / 2][a / 2] * (n / 2); } } printf("%lld\n",fenzi / fenmu);}int main(){ #ifdef ACM freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout); #endif // ACM pre_init(); int T; cin >> T; while (T--) { scanf("%d%d%d",&a,&b,&c); n = a + b + c; solve(); }}
0 0
- UVA 11255 - Necklace (等价置换)
- uva 11255 - Necklace(置换)
- UVA 11255 Necklace(Polya)
- UVA 11255 - Necklace(Ploya)
- uva 11255 Necklace
- uva 11255 Necklace (polya)
- uva 11255 Necklace
- poj Necklace of Beads 1286 (polya定理)置换群
- poj_1286 Necklace of Beads(置换群Polya定理)
- Necklace UVA
- Necklace UVA
- uva10294 Arif in Dhaka(置换的等价类计数)
- 关于置换等价类计数
- UVa Problem 10054 The Necklace (项链)
- UVA 10054 The Necklace(euler)
- UVA - 1156 Pixel Shuffle (置换+模拟)
- UVA - 10601 Cubes (组合+置换)
- UVA 11077 Find the Permutations(置换)
- MapReduce练习(二)
- CSV介绍
- Core Animation(二)动画基础部分
- poj 3264 Balanced Lineup简单线段树
- codeforces Rockethon 2015 - A. Game (= =)
- UVA 11255 - Necklace (等价置换)
- 博弈论(高僧斗法)
- HDU-找新朋友-素数筛选
- Think in Java(八):持有对象
- CentOs安装的eclipse双击无反应
- OpenStack架构
- 《HTTP权威指南》读书笔记(6)-实体和编码
- HDU-汉诺塔V-移动次数
- java中的super()是什么