博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
阅读量:7143 次
发布时间:2019-06-29

本文共 2223 字,大约阅读时间需要 7 分钟。

题目:

   

学习材料:

     

bzoj 1004:这道题注意考虑单位元的那个置换。

然后用 polya 定理即可。不动点个数是 dp 出来的,以保证合法。 dp 时注意 res -= tot 。

#include
#include
#include
#include
#define ll long longusing namespace std;const int N=65,M=25;int n,m,mod,s0,s1,s2,a[N],f[N],dp[2][M][M][M],ans;bool vis[N];void upd(int &x){x>=mod?x-=mod:0;}int pw(int x,int k){
int ret=1;while(k){
if(k&1)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=1;}return ret;}int solve(){ memset(vis,0,sizeof vis); memset(dp[0],0,sizeof dp[0]); dp[0][s0][s1][s2]=1; bool fx=0; int res=n; for(int i=1;i<=n;i++) if(!vis[i]) { int tot=0,cr=i; while(!vis[cr]) { tot++; vis[cr]=1; cr=a[cr]; } bool tf=!fx; memset(dp[tf],0,sizeof dp[tf]); for(int x0=s0;x0>=0;x0--) for(int x1=s1;x1>=0;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][0][0][0];}int main(){ scanf("%d%d%d%d%d",&s0,&s1,&s2,&m,&mod); n=s0+s1+s2; for(int j=1;j<=n;j++)a[j]=j; ans+=solve(); upd(ans); for(int i=1;i<=m;i++) { for(int j=1,d;j<=n;j++)scanf("%d",&d),a[d]=j; ans+=solve(); upd(ans); } ans=(ll)ans*pw(m+1,mod-2)%mod; printf("%d\n",ans); return 0;}
View Code

poj 2409:polya模板。

#include
#include
#include
#include
#define ll long longusing namespace std;const int N=35;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=1;while(k){
if(k&1)ret*=x;x*=x;k>>=1;}return ret;}int main(){ while(1) { scanf("%d%d",&m,&n);if(!n&&!m)return 0; ans=0; for(int i=1;i<=n;i++)ans+=pw(m,gcd(n,i)); if(n&1) ans+=n*pw(m,n+1>>1); else ans+=(n*pw(m,n>>1)>>1)+(n*pw(m,(n>>1)+1)>>1); printf("%lld\n",ans/(n<<1)); } return 0;}
View Code

 

转载于:https://www.cnblogs.com/Narh/p/10060460.html

你可能感兴趣的文章
阿里在使用一种更灵活的软件集成发布模式
查看>>
自己实现一个StringBuffer
查看>>
SpringBoot使用Nacos配置中心
查看>>
星矿科技完成千万元融资,专注明星IP价值商业化
查看>>
SOP 1.2.0 发布,开放平台解决方案项目
查看>>
Element 2.6.3 发布,基于 Vue 2.0 的桌面端组件库
查看>>
丰田研发智能汽车FV2,可利用肢体进行操控
查看>>
基于kubeadm的kubernetes高可用集群部署
查看>>
定位「数字化助手」,腾讯想用服务创新助力产业智慧升级
查看>>
golang之sync.Mutex互斥锁源码分析
查看>>
SAP增强的PA教材内容
查看>>
jQuery系列 第八章 jQuery框架Ajax模块
查看>>
OpenCV中原始图像加载与保存压缩技巧
查看>>
MySQL 8复制性能的增强
查看>>
C#使用Xamarin开发可移植移动应用(3.Xamarin.Views控件)附源码
查看>>
Java 模拟基于UDP的Socket通信
查看>>
我要做 Android 之Fragment
查看>>
有关 Windows Lite 的一切,只为对抗 Chrome OS?
查看>>
Android 自定义控件之SlidingMenuVertical顶部悬浮(垂直折叠抽屉,有滑动渐变回调,可自行添加渐变动画)...
查看>>
NG-ZORRO 7.0.1 发布,Ant Design 的 Angular 实现
查看>>