Summary of Polya theorem

Source: Internet
Author: User

The essence of Polya is in the search for the circulation section, which is often encountered in the problem of necklace dyeing.

When the necklace rotates, there are n permutations, and the number of cycles is GCD (n, i);

When the necklace is inverted, there are n permutations, where the number of the necklace beads is odd, the number of follow-up is n/2+1

When the necklace beads number is an even number, when the flip line through the beads, the number of links is n/2+1, otherwise, N/2;

1.POJ 1286:

The main topic: with three colors on the number of beads not more than 24 of the necklace dyeing, asked how many kinds of dyeing situation.

This problem is the most basic Polya theorem study, as long as the formula can be

#include <iostream>#include<stdio.h>#include<string.h>using namespacestd;Const Long LongMaxa = -;Long LongEdge[maxa];voidRotateLong LongNLong LongII) {     for(Long Longi =0; I < n; i++) {edge[(i+II)%n] =i; }}voidTurnLong LongNLong LongII) {     for(Long Longi = n1, j=0; I >=0; I--, J + +) {edge[(J+ II)%n] =i; }}Long LongVis[maxa];voidDfsLong Longi) {    if(Vis[i] = =1)return ; Vis[i]=1; DFS (Edge[i]);}intMain () {intN, M;  while(SCANF ("%d%d", &m, &n), n+m) {        if(n = =0) {printf ("0\n"); Continue; }        Long LongAns =0;  for(Long Longi =0; I < n; i++) {rotate (n, i); Long Longo =0; memset (Vis,0,sizeof(VIS));  for(Long LongK =0; k < n; k++){                if(vis[k]==0) {o++;                DFS (k); }            }            Long Longsum =1;  for(Long LongK =0; k < o; k++) {sum*=m; } ans+=sum; }         for(Long Longi =0; I < n; i++) {Turn (n, i); Long Longo =0; memset (Vis,0,sizeof(VIS));  for(Long LongK =0; k < n; k++){                if(vis[k]==0) {o++;                DFS (k); }            }            Long Longsum =1;  for(Long LongK =0; k < o; k++) {sum*=m; } ans+=sum; } cout<<ans/n/2<<Endl; }}
View Code

2.poj 2409

The main problem, with C color dye n beads composed of necklaces, is also the most basic Polya theorem investigation

#include <iostream>#include<stdio.h>#include<string.h>using namespacestd;Const Long LongMaxa = -;Long LongEdge[maxa];voidRotateLong LongNLong LongII) {     for(Long Longi =0; I < n; i++) {edge[(i+II)%n] =i; }}voidTurnLong LongNLong LongII) {     for(Long Longi = n1, j=0; I >=0; I--, J + +) {edge[(J+ II)%n] =i; }}Long LongVis[maxa];voidDfsLong Longi) {    if(Vis[i] = =1)return ; Vis[i]=1; DFS (Edge[i]);}intMain () {intN, M;  while(SCANF ("%d%d", &m, &n), n+m) {        if(n = =0) {printf ("0\n"); Continue; }        Long LongAns =0;  for(Long Longi =0; I < n; i++) {rotate (n, i); Long Longo =0; memset (Vis,0,sizeof(VIS));  for(Long LongK =0; k < n; k++){                if(vis[k]==0) {o++;                DFS (k); }            }            Long Longsum =1;  for(Long LongK =0; k < o; k++) {sum*=m; } ans+=sum; }         for(Long Longi =0; I < n; i++) {Turn (n, i); Long Longo =0; memset (Vis,0,sizeof(VIS));  for(Long LongK =0; k < n; k++){                if(vis[k]==0) {o++;                DFS (k); }            }            Long Longsum =1;  for(Long LongK =0; k < o; k++) {sum*=m; } ans+=sum; } cout<<ans/n/2<<Endl; }}
View Code

3.HDU 1812

How many ways are there to dye a n*n checkerboard with a C color?

In fact, this problem is can be seen as some (n+1)/2 string necklace, there are eight kinds of permutations, but the most pit is the large number of how to write all times out .... MJ System optimization also timed out ..... Playing the table is not so big, Java is a good solution ... Who writes who loves to write .... Anyway, I'm not writing a la La La.

Summary of Polya theorem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.