首页 技术 正文
技术 2022年11月14日
0 收藏 551 点赞 3,331 浏览 1389 个字

传送门

先考虑朴素dp,设\(f_{i,j}\)表示推了\(i\)次,前\(m\)个点的状态为二进制数\(j\)(这里记放C为1),转移的时候枚举下一位放什么,还要考虑是否满足C的个数\(\leq k\)

不过这个东西是环形的,考虑拆环为链,即找出所有合法状态\(j\),对于每个\(j\)初始化\(f_{0,j}=1\),然后从\(m+1\)位开始放,推\(n\)次,这个\(j\)的答案为\(f_{n,j}\)

因为\(n\)很大,同时\(j\)状态不超过32个,矩乘优化即可

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define LL long long
#define il inline
#define re register
#define db double
#define eps (1e-5)using namespace std;
const int N=35,mod=1000000007;
il LL rd()
{
re LL x=0,w=1;re char ch;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
struct martix
{
int n,m;
LL a[N][N];
martix(){}
il void clear(int nn,int mm)
{
n=nn,m=mm;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
a[i][j]=0;
}
il void init()
{
for(int i=0;i<n;i++) a[i][i]=1;
}
martix operator * (const martix &b) const
{
martix an;
an.clear(n,b.m);
for(int i=0;i<n;i++)
for(int j=0;j<b.m;j++)
for(int k=0;k<m;k++)
an.a[i][j]=(an.a[i][j]+a[i][k]*b.a[k][j]%mod)%mod;
return an;
}
martix operator ^ (const LL &bb) const
{
martix an,a;
an.clear(n,m),an.init(),a=*this;
LL b=bb;
while(b)
{
if(b&1) an=an*a;
a=a*a;
b>>=1;
}
return an;
}
}a,b;
LL n;
int nn,m,k;
il void initt()
{
b.clear(nn,nn);
for(int i=0;i<nn;i++)
{
int ii=(i|1)^1,cn=0;
while(ii) ++cn,ii-=ii&(-ii);
int j=i>>1;
if(cn<=k) b.a[i][j]=1;
if(cn+1<=k) b.a[i][j|(nn>>1)]=1;
}
b=b^n;
}int main()
{
n=rd(),m=rd(),k=rd();
nn=1<<m;
initt();
LL ans=0;
for(int i=0;i<nn;i++)
{
a.clear(1,nn);
a.a[0][i]=1;
a=a*b;
ans=(ans+a.a[0][i])%mod;
}
printf("%lld\n",ans);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902