zoukankan      html  css  js  c++  java
  • Burnside引理和polay计数 poj2409 Let it Bead

    题目描述

    "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.

    输入

    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.

    输出

    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.

    样例输入

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

    样例输出

    1
    2
    3
    5
    8
    13
    21

    提示


    前言:

      通过这道题深入了解一下burnside和polya,我尽力用简单朴素的方式理解

    简述题意:

      一个长为n的手镯,每个珠子可以染成k中颜色中的一种,求本质不同的染色方案有多少种?(可以旋转、翻转

    burnside是用来求关于一个置换群下有多少本质不同的染色方案的

    置换就是从一个顺序换成另一个顺序的操作,很多个置换就是置换群
    要使用burnside,第一步就是找到所有置换,一定要是所有的!不重不漏(这一点上我迷惑了挺久来着233
    就拿这道题来说,虽然看似就两种置换,旋转与翻转,但实际上要比两个多得多,转一个珠子,转两个。。。转n个,以及沿不同的轴翻转
    找置换的好方法就是标号,(接下来我们把环拆成一个序列,总之起点是一个固定的位置
    比如说n=4时,开始是1,2,3,4
    有一种置换就是什么都不做,也是转动0个珠子,这样就变成了1,2,3,4
    接下来还有3种转动方式,分别会变成
    2,3,4,1
    3,4,1,2
    4,1,2,3
    而翻转我们可以找到这4种:(你可以画画图233
    2,1,4,3
    4,3,1,2
    1,4,3,2
    3,2,1,4
    接下来你会发现无论你怎么组合以上的组合,得到的结果还在其中,这样我们找到的就是全部的置换了~
    解决了置换群,我们来解决不动点
    不动点是针对每种置换而言的,是指染色后,无论经过这个置换多少次,都不会变化的的染色方案
    比如当我们有2种颜色,对于置换2,1,4,3
    如果我们染成1,1,2,2,那么经过置换后还是能得到自己,还是1,1,2,2,这就是对于这个置换的一个不动点
    burnside是这么说的:置换群里所有置换的不动点数量的平均值就是本质不同的染色方案总数
    现在我们只需要求出对于每种置换的不动点数量就好了~
    首先要知道循环节,对于一个置换而言,假如说我们画一个箭头指向每个位置将要去的下一个位置
    就会发现他们形成了若干个环。
    比如2,1,4,3,就成了2个环,一个是1,2,一个是3,4,这就是两个循环节
    polya一个置换的不动点数就是k^x,其中k是颜色数,x是循环节数
    使用这两个定理我们就能解决这道题了!
    首先对于一个转动i个珠子的旋转来说,循环节数是gcd(i,n)
    让所有珠子从0到n-1标号,设一个循环节的起点是x,转了t次后第一次回来
    有x=(x+t*i)%n,所以(t*i)%n==0,t*i=k*n也就是说t*i=lcm(i,n)
    那么循环节数量n/t就是gcd(i,n)了
    对于翻转,我们分奇偶讨论,
    奇数只能选择一个珠子和对应的边作为对称轴,一共n个,每个有(n+1)/2个循环节
    偶数可以选择两个珠子作为对称轴,一共n/2个,每个有(n+2)/2个循环节
    还可以选择两个边作为对称轴,一共n/2个,每个有n/2个循环节
    看代码吧:
     1 #include<cstdio>
     2 #define ll long long
     3 using namespace std;
     4 int n,k;
     5 ll ans;
     6 ll gcd(ll a,ll b){
     7     if(!b)return a;
     8     return gcd(b,a%b);
     9 }
    10 ll ksm(ll x,ll t){
    11     ll ans=1;
    12     for(;t;t>>=1,x*=x)if(t&1)ans*=x;
    13     return ans;
    14 }
    15 int main(){
    16     while(scanf("%d%d",&k,&n)){
    17         if(n==0&&k==0)break;
    18         ans=0;
    19         for(int i=1;i<=n;i++)ans+=ksm(k,gcd(i,n));
    20         if(n&1)ans+=ksm(k,(n+1)/2)*n;
    21         else{
    22             ans+=ksm(k,(n+2)/2)*n/2;
    23             ans+=ksm(k,n/2)*n/2;
    24         }
    25         ans/=2*n;
    26         printf("%lld
    ",ans);
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    IOCP十:Client退出后投递WSARecv
    IOCP九:Client退出后投递WSASend
    IOCP九:Client退出后投递WSASend
    CPU线程调度
    CPU线程调度
    windows的磁盘操作之八——格式化分区的思考
    windows的磁盘操作之八——格式化分区的思考
    windows的磁盘操作之六——获取系统所在物理磁盘号
    windows的磁盘操作之六——获取系统所在物理磁盘号
    windows的磁盘操作之七——获取当前所有的物理磁盘号
  • 原文地址:https://www.cnblogs.com/2017SSY/p/10519691.html
Copyright © 2011-2022 走看看