poj2409(polya计数 套模版)

来源:互联网 发布:js调用身份证读取器 编辑:程序博客网 时间:2024/06/05 15:58
http://poj.org/problem?id=2409
Let it Bead
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 3549Accepted: 2281

Description

"Let it Bead"company is located upstairs at 700 Cannery Row in Monterey, CA. Asyou can deduce from the company name, their business is beads.Their PR department found out that customers are interested inbuying colored bracelets. However, over 90 percent of the targetaudience insists that the bracelets be unique. (Just imagine whathappened if two women showed up at the same party wearing identicalbracelets!) It's a good thing that bracelets can have differentlengths and need not be made of beads of one color. Help the bossestimating maximum profit by calculating how many differentbracelets can be produced.

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

Input

Every line of theinput file defines a test case and contains two integers: thenumber of available colors c followed by the length of thebracelets s. Input is terminated by c=s=0. Otherwise, both arepositive, and, due to technical difficulties in thebracelet-fabrication-machine, cs<=32, i.e. their product doesnot exceed 32.

Output

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

Sample Input

1 12 12 25 12 52 66 20 0

Sample Output

123581321

Source

UlmLocal 2000

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

解析: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 longcount=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;

}


原创粉丝点击