do_while_true

一言(ヒトコト)

「题解」Codeforces 1152F2 Neko Rules the Catniverse (Large Version)

扫值域,然后考虑逐步 \(a\) 通过插数给插出来。然后发现如果选,那么可以插入的位置就是 \([i-m+1,i-1]\) 里面选了的数的个数再 \(+1\)(它们后面都能插入 \(i\),还有直接插入到最开头的一种情况)

那么就有 dp \(f_{i,j,S}\) 表示考虑到了 \(i\),插入了 \(j\) 个数,\([i-m+1,i-1]\) 的选择情况是 \(S\). 

列出 dp 之后把后两维看成一个列向量,矩阵快速幂即可。

其实,还挺好写的。

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pil>vpil;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=1000000007;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
	int s=1;
	while(y){
		if(y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return s;
}
inline int bit(int x){
	return 1<<x;
}
inline int all(int x){
	return (1<<x)-1;
}
const int K=210;
int n,m,k;
int p[K][K],tot;
int a[K][K],b[K][K],c[K][K];
void mul(int f[K][K],int g[K][K]){
	for(int i=1;i<=tot;i++)
		for(int j=1;j<=tot;j++)
			for(int k=1;k<=tot;k++)
				cadd(c[i][j],1ll*f[i][k]*g[k][j]%mod);
	memcpy(f,c,sizeof(c));
	memset(c,0,sizeof(c));
}
signed main(){
	#ifdef do_while_true
//		assert(freopen("data.in","r",stdin));
//		assert(freopen("data.out","w",stdout));
	#endif
	read(n,k,m);
	for(int i=0;i<=k;i++)	
		for(int j=0;j<=all(m);j++)
			p[i][j]=++tot;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=all(m);j++){
			a[p[i][j]][p[i][j>>1]]=1;
			if(i<k)a[p[i][j]][p[i+1][(j>>1)|bit(m-1)]]=__builtin_popcount(j)+1;
		}
	}
	for(int i=1;i<=tot;i++)b[i][i]=1;
	while(n){
		if(n&1)mul(b,a);
		mul(a,a);
		n>>=1;
	}
	int ans=0;
	for(int i=0;i<=all(m);i++)
		cadd(ans,b[1][p[k][i]]);
	cout << ans << '\n';
    #ifdef do_while_true
		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}
posted @ 2023-02-24 14:57  do_while_true  阅读(10)  评论(0编辑  收藏  举报