UVA 11255 - Necklace (等价置换)
2015-02-08 23:43
417 查看
Problem C - Necklace
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
Sample output
6
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)这个置换,别漏了。
代码:
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
Sample output
6
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 double const 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 [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(); } }
相关文章推荐
- uva 11255 - Necklace(置换)
- uva11255 - Necklace 项链旋转翻转 置换
- UVA11255 necklace (polya定理)
- UVA - 11255 Necklace (poolya计数+组合数学)
- UVA 11255 Necklace(Burnside引理)
- uva 11255 Necklace
- UVA 11255 Necklace
- Necklace UVA - 11255
- UVA 11255 Necklace(Polya)
- UVA - 11255 Necklace 母函数型polya
- uva11255 Necklace(polya+组合数学)
- Necklace UVA - 11255(polya计数)
- uva 11255 Necklace (polya)
- UVA 11255 - Necklace(Ploya)
- UVA 11255 Necklace(每种颜色珠子个数限制、Polya原理、组合数)
- UVA 11255 Necklace
- UVA 11077 Find the Permutations(置换+dp)
- uva 11077 - Find the Permutations(置换+dp)
- UVA 12103/poj 3128/hdu 1975/UVALive 3641 Leonardo's Notebook 置换
- UVA 10054 - The Necklace 欧拉回路