[Arc058E] Iroha and Haiku

[Arc058E] Iroha and Haiku

题目大意

问有多少\(n\)个数的正整数序列,每个数在\([1,10]\)之间,满足存在\(x,y,z,w\)使得\(x\to y-1,y\to z-1,z\to w\)的和分别为\(X,Y,Z\)
\(X,Z\leq 5,Y\leq 7\)

试题分析

由于发现\(X+Y+Z\)\(a_i\)很小,所以考虑状态压缩,可以用位数来表示数字,比如\(5=10000,1=1\)
然后不合法方案数比合法方案数好求,所以直接求不和法即可。

#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
 
#define LL long long
 
inline LL read(){
	LL x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const LL INF=9999999;
const LL MAXN=100010;
const LL Mod = 1e9+7;
 
LL N,X,Y,Z;
LL Finall,MAX;
LL f[41][(1<<18)];
LL ans=0;
 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); X=read(),Y=read(),Z=read();
	Finall=(1LL<<(X-1))|(1LL<<(X+Y-1))|(1LL<<(X+Y+Z-1));
	MAX=(1LL<<(X+Y+Z))-1; f[0][0]=1; LL Pw=1;
	for(LL i=0;i<N;i++){
		Pw=Pw*10LL%Mod;
		for(LL j=0;j<=MAX;j++){
			if(!f[i][j]) continue;
			for(LL k=1;k<=10;k++){
				LL x=MAX&((j<<k)|(1LL<<(k-1)));
				if((x&Finall)==Finall) continue;
				f[i+1][x]+=f[i][j]; f[i+1][x]%=Mod;
			} 
		} //cout<<endl; system("pause");
	} for(LL j=0;j<=MAX;j++) (ans+=f[N][j])%=Mod;
	printf("%lld\n",(Pw-ans+Mod)%Mod);
	return 0;
}
posted @ 2018-09-02 11:16  wxjor  阅读(446)  评论(0编辑  收藏  举报