您的位置:首页 > 其它

【裸polya定理】poj 2409 Let it Bead

2015-09-17 17:51 363 查看
poj 2409 Let it Bead

http://poj.org/problem?id=2409

思路

polya定理经典问题:c种颜色的珠子组成长为s的项链的方案数,项链没有方向和起始位置

参考代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

typedef long long ll;
const int _max = 20 + 10;

int n,c,s;

ll gcd(ll a,ll b){return b ? gcd(b,a%b):a;}
ll polya(int c, int s){//c种颜色去染s个珠子串成的项链
ll p[64];p[0] = 1;//power of c
for(int k = 0; k < s; ++ k) p[k+1] = p[k]*c;
//reflection part
ll count = s&1 ? s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);
//rotation part
for(int k = 1;k <= s; ++ k)count+=p[gcd(k,s)];
count /= 2 * s;
return count;
}

int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
while(scanf("%d%d",&c,&s) == 2 && (s||n)){
printf("%lld\n",polya(c,s));
}
return 0;
}


加粗
Ctrl + B


斜体
Ctrl + I


引用
Ctrl + Q


插入链接
Ctrl + L


插入代码
Ctrl + K


插入图片
Ctrl + G


提升标题
Ctrl + H


有序列表
Ctrl + O


无序列表
Ctrl + U


横线
Ctrl + R


撤销
Ctrl + Z


重做
Ctrl + Y
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  polya定理