uva 11255 Necklace

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.

Rotating and turning over a necklace


The following figure shows all possible necklaces formed by 3 white pearls, 2 grey pearls and 1 black pearl.

All necklaces formed by3 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

这题因为没学过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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值