cf1027E Inverse Coloring dp

版权声明:虽然是个蒟蒻但是转载还是要说一声的哟 https://blog.csdn.net/jpwang8/article/details/86183442

Description


You are given a square board, consisting of n n n rows and n n n columns. Each tile in it should be colored either white or black.

Let’s call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.

Let’s call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least k k k tiles.

Your task is to count the number of suitable colorings of the board of the given size.

Since the answer can be very large, print it modulo 998244353 998244353 998244353 .

Solution


首先要知道,如果存在一行和一列01组成的数列x[]y[],令a[i,j]=x[i]^y[i]即可得到满足条件1和2 的矩形
对于第三个条件考虑dp,设f[i,j,k]表示满足长度恰好为i,最大连续为j,末尾连续为k的01数组数量,我们统计一下乘起来就可以了

Code


#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (register int i=st,_=ed;i<=_;++i)
#define fill(x,t) memset(x,t,sizeof(x))

typedef long long LL;
const int MOD=998244353;
const int N=505;

LL f[2][N][N],g[N][N];

void upd(LL &x,LL v) {
	x=x+v; x%=MOD;
}

int main(void) {
	freopen("data.in","r",stdin);
	int n,m; scanf("%d%d",&n,&m);
	f[0][0][0]=1;
	rep(i,0,n) {
		int x=i&1;
		fill(f[!x],0);
		rep(j,0,i) {
			rep(k,0,std:: min(i,j)) {
				upd(f[!x][std:: max(j,k+1)][k+1],f[x][j][k]);
				upd(f[!x][std:: max(j,1)][1],f[x][j][k]);
				upd(g[i][j],f[x][j][k]);
			}
		}
	}
	LL ans=0;
	rep(i,1,n) rep(j,1,n) {
		if (i*j<m) upd(ans,1LL*g[n][i]*g[n][j]%MOD);
		else break;
	}
	ans=499122177LL*ans%MOD;
	printf("%lld\n", ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/jpwang8/article/details/86183442