CF1051D Bicolorings 递推

考试T2,随便推一推就好了~

code:

#include <bits/stdc++.h>  
#define N 1015 
#define mod 998244353    
#define ll long long  
#define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout) 
using namespace std; 
ll f[N][N<<1][2][2];      
int main() 
{ 
	// setIO("army"); 
	int i,j,n=2,m,k; 
	scanf("%d%d",&m,&k);       
	f[1][1][0][0]=1ll;  
	f[1][1][1][1]=1ll;  
	f[1][2][1][0]=1ll; 
	f[1][2][0][1]=1ll;   
	for(i=1;i<m;++i) 
	{
		for(j=1;j<=k;++j) 
		{      
			(f[i+1][j][0][0]+=(f[i][j][0][0]+f[i][j][0][1]+f[i][j][1][0])%mod)%=mod;     
			(f[i+1][j][1][1]+=(f[i][j][0][1]+f[i][j][1][0]+f[i][j][1][1])%mod)%=mod;   
			(f[i+1][j][0][1]+=f[i][j][0][1])%=mod;            
			(f[i+1][j][1][0]+=f[i][j][1][0])%=mod;   
			(f[i+1][j+1][0][0]+=f[i][j][1][1])%=mod;  
			(f[i+1][j+1][1][1]+=f[i][j][0][0])%=mod;      
			(f[i+1][j+1][0][1]+=(f[i][j][0][0]+f[i][j][1][1])%mod)%=mod;   
			(f[i+1][j+1][1][0]+=(f[i][j][0][0]+f[i][j][1][1])%mod)%=mod;     
			(f[i+1][j+2][0][1]+=f[i][j][1][0])%=mod;  
			(f[i+1][j+2][1][0]+=f[i][j][0][1])%=mod;    
		}
    }       
	printf("%lld\n",(f[m][k][0][0]+f[m][k][1][1]+f[m][k][0][1]+f[m][k][1][0])%mod);    
	return 0; 
}

  

posted @ 2019-10-14 14:00  EM-LGH  阅读(90)  评论(0编辑  收藏  举报