您的位置:首页 > 其它

uva 11255 Necklace

2014-08-25 20:46 676 查看
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 cblack
pearls in a single line.

Sample input

2

3 2 1

2 2 2

Sample output

6

11

这题因为没学过burnside,所以不会做,以为用波利亚可以做,但是想很久还是不知道怎么做。唉,数学本来就差,burnside就很看不懂了,最后只知道做这题的步骤了。。。先把它记录下来再说吧。。。
burnsize引理公式:ans = 1/|G|*(z1+z2+z3+...+zn),|G|是置换群的大小,zn就是从每个置换里求得的。
枚举每个置换:
1、首先,考虑旋转的置换。旋转的置换里的循环节的长度是一样的,记为L。遍历所有颜色的个数color[i],如果color[i]%L != 0,则zn = 0。
否则,把color[i]/L保存到b[i]中,记sum = b[0]+...+b[i],最后zn=C[sum][b[0]]*C[sum-b[0]][b[1]]*..C[sum-b[0]..-b[i-1]][b[i]]
例如:
{(1,2),(3,4),(5,6)} 则L = 2
color : 4 , 6 , 2
b : 2 , 3 , 1
sum = 2+3+1 = 6
zn = C[6][2]*C[4][3]*C[1][1],C[i][j]为组合数,从i个数中去j个数。
2、其次,考虑翻转的置换。当翻转的对称轴上有点时,首先枚举点的颜色,然后对应的颜色数减一,L为不在对称轴上的循环节的长度,再继续跟上面一样算。
例如:
{(1,2) , (3) , (4)} 则L = 2
color : 5 6 3 , 假设3、4用掉第一种和第三种颜色,则:
color : 4 6 2

b : 2 , 3 , 1
sum = 2+3+1 = 6
zn = C[6][2]*C[4][3]*C[1][1]
3、把每个置换算得的zn相加,用公式就可以算出答案。

唉,数学太差了。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define ll long long
const int maxn = 120;
int a[3] , sum;
ll C[maxn][maxn];

void getC(){//预处理组合数
memset(C, 0 ,sizeof C);
C[0][0] = 1;
C[1][1] = 1;
for(int i = 1; i < maxn; i++) C[i][0] = 1;
for(int i = 2; i < maxn; i++){
for(int j = 1; j <= i; j++){
C[i][j] = C[i-1][j-1]+C[i-1][j];
}
}
}

int gcd(int a , int b){
if(b == 0) return a;
return gcd(b , a%b);
}

ll solve(int k){//求zn,k为循环节长度
int b[3] , s = 0;
for(int i = 0; i < 3; i++){
if(a[i]%k != 0) return 0;
s += a[i]/k;
b[i] = a[i]/k;
}
ll ans = 1;
for(int i = 0; i < 3; i++){
ans *= C[s][b[i]];
s -= b[i];
}
return ans;
}

void computing(){
sum = a[0]+a[1]+a[2];
ll ans = 0;
for(int i = 1; i <= sum; i++){
int g = sum/gcd(sum ,  i);
ans += solve(g);
}
if(sum%2 == 0){
for(int i = 0; i < 3; i++){
if(a[i] < 1) continue;
a[i] -= 1;
for(int j = 0; j < 3; j++){
if(a[j] < 1) continue;
a[j] -= 1;
ans += (sum/2)*solve(2);
a[j] += 1;
}
a[i] += 1;
}
ans += (sum/2)*solve(2);
}else{
for(int i = 0; i < 3; i++){
if(a[i] < 1) continue;
a[i] -= 1;
ans += sum*solve(2);
a[i] += 1;
}
}
printf("%lld\n" , ans/(2*sum));
}

int main(){
getC();
int N;
scanf("%d" , &N);
while(N--){
scanf("%d%d%d" , &a[0] , &a[1] , &a[2]);
computing();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: