poj2409(polya计数 套模版)

http://poj.org/problem?id=2409
Let it Bead
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 3549Accepted: 2281

Description

"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.

A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.

Input

Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.

Output

poj2409(polya计数 <wbr>套模版)For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.

Sample Input

1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0

Sample Output

1
2
3
5
8
13
21

Source

题意:给定色彩种数和环上的珠子总数,问有几许种染色规划(经由过程扭转和翻转雷同的算同一种)。

解析:polya定理。在这里只谈一下polya定理是如何应用的。对于排成一排的带编号的小球,遵守某一种规划改变此中一些球的放置次序,可以称之为置换。每一种置换办法可以用两排数字來默示,第一排数字和第二排数字一一对应,第一排数字默示小球的本来地位(1~n),第二排数字默示小球互换后的地位。如今我们有n个小球,m种色彩。有k种置换办法,我们认为能经由过程置换办法互换地位后变成同一种染色景象(色彩的分列状况雷同,忽视小球编号),则我们认为这些互相经由过程置换能达到的状况为同一种染色办法。我们如今请求统共有几许种染色办法。要策画办法数,我们先要策画k种置换办法中每种置换办法中含有的环数,即建树一个图,有n个点,把每个置换办法两排数字中的高低一一对应的数字对算作边的出发点和终点,策画这个图中有几个环。我们设环数分别为c1~ck。那么染色办法数为(m^c1+m^c2+...+m^ck)/k。以上就是polya定理,这里要重视的是置换办法凑集必须是群,须要满足封闭性,即若是把经由过程该凑集中的若干个办法连气儿进行置换紧缩成一个置换办法(用两排数子默示),那么这种新的置换办法也必须属于该凑集。

这道题可以如许以来就是一道赤裸裸的polya定理题了。


这题是完完全全套模版做的真是爽啊,可以说第一次照做模版做吧。。

吉大的模版。。。

#include

#include

#include

using namespace std;

int gcd(int a,int b)

{

    return b?gcd(b,a%b):a;

}

int main()

{

    int c,s;

    while(scanf("%d%d",&c,&s)!=EOF)

    {

        if(c==0&&s==0)

        {

            break;

        }

        int k;

        long long p[64];

        p[0]=1;

        for(k=0;k

        {

            p[k+1]=p[k]*c;

        }

        long long count=s&1?s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);

        for(k=1;k<=s;k++)

        {

            count+=p[gcd(k,s)];

        }

        count/=2*s;

        printf("%lld\n",count);

    }

    return 0;

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值