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://www.cnblogs.com/nietzsche-oier/p/6883880.html
https://files-cdn.cnblogs.com/files/HocRiser/Burnside.pdf
bzoj 1004:这道题注意考虑单位元的那个置换。
然后用 polya 定理即可。不动点个数是 dp 出来的,以保证合法。 dp 时注意 res -= tot 。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=,M=;
int n,m,mod,s0,s1,s2,a[N],f[N],dp[][M][M][M],ans;
bool vis[N];
void upd(int &x){x>=mod?x-=mod:;}
int pw(int x,int k)
{int ret=;while(k){if(k&)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=;}return ret;}
int solve()
{
memset(vis,,sizeof vis);
memset(dp[],,sizeof dp[]); dp[][s0][s1][s2]=;
bool fx=; int res=n;
for(int i=;i<=n;i++)
if(!vis[i])
{
int tot=,cr=i;
while(!vis[cr])
{
tot++; vis[cr]=;
cr=a[cr];
}
bool tf=!fx; memset(dp[tf],,sizeof dp[tf]);
for(int x0=s0;x0>=;x0--)
for(int x1=s1;x1>=;x1--)
{
int x2=res-x0-x1,d;
if(x2>s2||!(d=dp[fx][x0][x1][x2]))continue;
if(x0>=tot)dp[tf][x0-tot][x1][x2]+=d,upd(dp[tf][x0-tot][x1][x2]);
if(x1>=tot)dp[tf][x0][x1-tot][x2]+=d,upd(dp[tf][x0][x1-tot][x2]);
if(x2>=tot)dp[tf][x0][x1][x2-tot]+=d,upd(dp[tf][x0][x1][x2-tot]);
}
fx=tf; res-=tot;
}
return dp[fx][][][];
}
int main()
{
scanf("%d%d%d%d%d",&s0,&s1,&s2,&m,&mod);
n=s0+s1+s2;
for(int j=;j<=n;j++)a[j]=j;
ans+=solve(); upd(ans);
for(int i=;i<=m;i++)
{
for(int j=,d;j<=n;j++)scanf("%d",&d),a[d]=j;
ans+=solve(); upd(ans);
}
ans=(ll)ans*pw(m+,mod-)%mod;
printf("%d\n",ans);
return ;
}
poj 2409:polya模板。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=;
int n,m; ll ans;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll pw(ll x,int k)
{ll ret=;while(k){if(k&)ret*=x;x*=x;k>>=;}return ret;}
int main()
{
while()
{
scanf("%d%d",&m,&n);if(!n&&!m)return ;
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("%lld\n",ans/(n<<));
}
return ;
}
bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群的更多相关文章
- bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...
- BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )
题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...
- [BZOJ 1004] [HNOI2008] Cards 【Burnside引理 + DP】
题目链接:BZOJ - 1004 题目分析 首先,几个定义和定理引理: 群:G是一个集合,*是定义在这个集合上的一个运算. 如果满足以下性质,那么(G, *)是一个群. 1)封闭性,对于任意 a, b ...
- BZOJ 1004: [HNOI2008]Cards
Description 给你一个序列,和m种可以使用多次的置换,用3种颜色染色,求方案数%p. Sol Burnside定理+背包. Burnside定理 \(N(G,\mathbb{C})=\fra ...
- BZOJ 1004 HNOI2008 Cards Burnside引理
标题效果:特定n张卡m换人,编号寻求等价类 数据保证这m换人加上置换群置换后本身构成 BZOJ坑爹0.0 条件不那么重要出来尼玛怎么做 Burnside引理--昨晚为了做这题硬啃了一晚上白书0.0 都 ...
- BZOJ 1004: [HNOI2008]Cards(群论)
好吧我就是蒟蒻根本没听说过群论(虽说听叉姐说几万年都不会考) 我也讲不太来,直接戳VFK大神的blog啦 = = http://vfleaking.blog.163.com/blog/static/1 ...
- BZOJ 1004: [HNOI2008]Cards [Polya 生成函数DP]
传送门 题意:三种颜色,规定使用每种颜色次数$r,g,b$,给出一个置换群,求多少种不等价着色 $m \le 60,\ r,g,b \le 20$ 咦,规定次数? <组合数学>上不是有生成 ...
- POJ 2409 Let it Bead [置换群 Polya]
传送门 题意:$m$种颜色$n$颗珠子,定义旋转和翻转两种置换,求不等价着色数 暴力求每个置换的循环节也许会$T?$ 我们可以发现一些规律: 翻转: $n$为奇数时每个置换有$1+\frac{n-1} ...
- bzoj 1004 1004: [HNOI2008]Cards burnside定理
1004: [HNOI2008]Cards Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1668 Solved: 978[Submit][Stat ...
随机推荐
- Effective C++ 条款02:尽量以const,enum,inline替换 #define
换一种说法就是宁可以编译器替换预处理器 举例 #define ASPECT_RATIO 1.653 记号ASPECT_RATIO也许从未被编译器看见:也许在编译起开始处理源码前它就被预处理器移走了,于 ...
- gcm 被微信弃用的原因
作者:feng xixi链接:https://www.zhihu.com/question/21514839/answer/18496706来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...
- Jar 包 及运行Jar包 - 转载
Eclipse的jar file和Runnable JAR file的区别 - 及bat运行Runnable JAR文件 1.两种jar的区别 jar file是最普通的jar包,即平时我们工程中li ...
- Android中获取手机电量信息
有些时候我们需要在我们的应用上为用户展示当前手机的电量,这时候我们就需要用到广播了,我们都知道在动态注册广播的时候,我们需要传入一个BroadcastReceiver类对象,还有一个意图过滤器Inte ...
- 一块网卡多个IP实现
////////////////////////////写在前面//////////////////////////////////////////// 需要注意,这里我们是一块网卡多个IP,而并非是 ...
- 使用Mybatis时报错Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
首先保证sql语句在oracle中的编写是正确的,然后在配置文件中插入时就报这样的错误.有可能是因为sql语句后面多了“:”分号,在标签中写分号是错的.如果我写成了 insert into emplo ...
- HTTP Status 500 - com.opensymphony.xwork2.ActionSupport.toAddPage()
使用struts2过程中碰到以下错误 HTTP Status 500 - com.opensymphony.xwork2.ActionSupport.toAddPage() type Exceptio ...
- Eclipse工具栏上android的机器人小图标不见了
可以通过「Window」⇒「Customize Perspective」⇒「Tool Bar Visibility」Tab画面上选择Android SDK and AVD Manager来显示
- cenOs7安装redis
1.安装redis redis 目前没有官方 RPM 安装包,我们需要从源代码编译,而为了要编译就需要安装 Make 和 GCC. 如果没有安装过 GCC 和 Make,那么就使用 yum 安装 -- ...
- Intellij IDEA 配置Subversion插件实现步骤详解
在使用Intellij的过程中,突然发现svn不起效了,在VCS–>Checkout from Version Control中也未发现Subversion这一项.如下图: 一.原因查找 经过 ...