【裸polya定理】poj 2409 Let it Bead

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值