cf1027E Inverse Coloring dp

123 篇文章 0 订阅
28 篇文章 0 订阅

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值