【题解】 CF1027E Inverse Coloring

\(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 .

(果然还是太懒了)

\(Sample\) \(Input\):

1 1

\(Sample\) \(Output\):

0

\(Solution\)

首先考虑怎么求把一段i涂成一种颜色的方案数:

\(f[i][j]\)表示连续段长度\(<=i\),前j个的方案数

\(f[i][j]=\sum_{l=1}^{i}f[i][j-l]\)

然后这样预处理出第一列的情况数,在考虑后面每一列

连续长度为(K-1)/当前连续长度。

然后对横着做一遍连续长度小于连续长度的DP

#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n,K,now,sum,ans;
const int N=2000,p=998244353;
int f[N+5],s[N+5];
signed main(){
    if(fopen("fairy.in","r")){
        freopen("fairy.in","r",stdin);
        freopen("fairy.out","w",stdout);
    }
    scanf("%lld%lld",&n,&K);
    K--;
    for(int i=1;i<=min(K,n);++i){
        f[0]=1;sum=0;
        for(int j=1;j<=i;++j){
            f[j]=(f[j-1]*2)%p;
            sum=(sum+f[j])%p;
        }
        for(int j=i+1;j<=n;++j){
            f[j]=sum;
            sum=((sum-f[j-i])%p+p)%p;
            sum=(sum+f[j])%p;
        }
        s[i]=((f[n]-now)%p+p)%p;
        now=f[n];
    }
    for(int i=1;i<=min(K,n);++i){
        int limit=min(K/i,n);
        f[1]=s[i];sum=s[i];
        for(int j=2;j<=limit;++j){
            f[j]=(f[j-1]*2)%p;
            sum=(sum+f[j])%p;
        }
        for(int j=limit+1;j<=n;++j){
            f[j]=sum;
            sum=((sum-f[j-limit])%p+p)%p;
            sum=(sum+f[j])%p;
        }
        ans=(ans+f[n])%p;
    }
    printf("%lld\n",ans);
    return 0;
}

转载于:https://www.cnblogs.com/JCNL666/p/10688040.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值