bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004
关于置换群:https://www.cnblogs.com/nietzsche-oier/p/6883880.html
https://files-cdn.cnblogs.com/files/HocRiser/Burnside.pdf
原来 burnside 引理中的“不动点”是指一种不变化的方案啊;
这道题就用 burnside 引理,但给出的 m 个置换还不是置换群,需要再加一个单位元,即 \( a[i] = i \) 的置换;
用三维DP求出每种置换的“不动点”个数,枚举可以通过记录总数而减少一维。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const xn=,xm=;
int n,m,sr,sb,sg,a[xn],f[xm][xm][xm],mod,tot;
bool vis[xn];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
ll pw(ll a,int b)
{
ll ret=;
for(;b;b>>=,a=(a*a)%mod)if(b&)ret=(ret*a)%mod;
return ret;
}
int upt(int x){while(x>=mod)x-=mod; while(x<)x+=mod; return x;}
void dfs(int x)
{
tot++; vis[x]=;
if(!vis[a[x]])dfs(a[x]);
}
int main()
{
sr=rd(); sb=rd(); sg=rd(); m=rd(); mod=rd();
n=sr+sb+sg; m++;
for(int i=;i<=m;i++)
{
memset(vis,,sizeof vis);
memset(f,,sizeof f); f[][][]=;//
if(i==m)for(int j=;j<=n;j++)a[j]=j;
else for(int j=;j<=n;j++)a[j]=rd(),vis[j]=;
tot=; int res=;
for(int j=;j<=n;j++)
{
if(vis[j])continue;
tot=; dfs(j); res+=tot;
for(int j=sr;j>=;j--)
for(int k=sb;k>=;k--)
//for(int l=sg;l>=0;l--)
{
int l=res-j-k; if(l<)continue;
if(j>=tot)f[j][k][l]=upt(f[j][k][l]+f[j-tot][k][l]);
if(k>=tot)f[j][k][l]=upt(f[j][k][l]+f[j][k-tot][l]);
if(l>=tot)f[j][k][l]=upt(f[j][k][l]+f[j][k][l-tot]);
}
}
}
printf("%lld\n",(ll)f[sr][sb][sg]*pw(m,mod-)%mod);
return ;
}
题目:http://poj.org/problem?id=2409
Polya 定理裸题;
gcd 可以从模的剩余系的角度来看;
注意加上翻转后有 2n 个置换。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=;
int n,m;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int pw(int a,int b)
{
int ret=;
for(;b;b>>=,a=a*a)if(b&)ret=ret*a;
return ret;
}
int main()
{
while()
{
scanf("%d%d",&m,&n);
if(!m&&!n)return ;
int ans=;
for(int i=;i<=n;i++)ans+=pw(m,gcd(n,i));
if(n%)ans+=n*pw(m,n/+);
else ans+=n/*pw(m,n/)+n/*pw(m,n/+);
printf("%d\n",ans//n);//2n
}
return ;
}
bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群的更多相关文章
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- POJ 2409 Let it Bead [置换群 Polya]
传送门 题意:$m$种颜色$n$颗珠子,定义旋转和翻转两种置换,求不等价着色数 暴力求每个置换的循环节也许会$T?$ 我们可以发现一些规律: 翻转: $n$为奇数时每个置换有$1+\frac{n-1} ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- bzoj 1004 Cards
1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...
- POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...
- POJ 2409 Let it Bead 组合数学
题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...
随机推荐
- vue proxyTable
Vue-cli proxyTable 解决开发环境的跨域问题 字数474 阅读1685 评论1 喜欢3 和后端联调时总是会面对恼人的跨域问题,最近基于Vue开发项目时也遇到了这个问题,两边各自想了一堆 ...
- Django之便签生成
myblog_tag.py #coding:utf-8 __author__ = 'similarface'from django import template register=template. ...
- linux下ejabberd框架搭建
ejabberd为erlang的IM的开源框架,一直想找个时间研究研究: 1.下载Ejabberd安装包 wget http://www.process-one.net/downloads/ejabb ...
- Docker入门系列5:常见问题小结
重启容器 再次运行容器: docker start container_id 然后 docker attach container_id 就可以继续下命令了. [编辑]命名 --name [编辑]端口 ...
- PowerBuilder -- 数据窗口
获取数据窗口列数 ls_colnum= integer(this.Describe("DataWindow.Column.Count")) 获取数据窗口列名 ls_colName ...
- shell 获取当前svn代码目录版本号
在当前svn代码目录下执行以下命令: svn info | grep "Last Changed Rev:" | awk -F ': ' '{print $2}' > svn ...
- Spring mybatis自动扫描dao
Spring注解方式会出现找不到dao的bean的情况 [解决方案] 在mybatis配置文件中加入以下绑定dao的方式: <!-- mapper接口namepspace绑定方式 -->& ...
- python 基础 2.6 break用法
python中最基本的语法格式大概就是缩进了.python中常用的循环:for循环,if循环.一个小游戏说明for,if ,break的用法. 猜数字游戏: 1.系统生成一个20以内的随机数 2.玩家 ...
- protect,internal的区别
protected: 爷爷有一张银行卡,爸爸可以用,儿子也可以用,隔壁老王不可以用(因为老王跟爷爷没有继承关系) internal: 王总有一张银行卡,秘书可以用,经理可以用,王总儿子不可以用(因为银 ...
- redis自启动
$ vi /etc/init.d/redis # chkconfig: 2345 90 10 # description: Redis is a persistent key-value databa ...