【题解】 CF1027E Inverse Coloring

快来打我* 2022-01-12 03:21 206阅读 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 .

(果然还是太懒了)

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

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int n,K,now,sum,ans;
  5. const int N=2000,p=998244353;
  6. int f[N+5],s[N+5];
  7. signed main(){
  8. if(fopen("fairy.in","r")){
  9. freopen("fairy.in","r",stdin);
  10. freopen("fairy.out","w",stdout);
  11. }
  12. scanf("%lld%lld",&n,&K);
  13. K--;
  14. for(int i=1;i<=min(K,n);++i){
  15. f[0]=1;sum=0;
  16. for(int j=1;j<=i;++j){
  17. f[j]=(f[j-1]*2)%p;
  18. sum=(sum+f[j])%p;
  19. }
  20. for(int j=i+1;j<=n;++j){
  21. f[j]=sum;
  22. sum=((sum-f[j-i])%p+p)%p;
  23. sum=(sum+f[j])%p;
  24. }
  25. s[i]=((f[n]-now)%p+p)%p;
  26. now=f[n];
  27. }
  28. for(int i=1;i<=min(K,n);++i){
  29. int limit=min(K/i,n);
  30. f[1]=s[i];sum=s[i];
  31. for(int j=2;j<=limit;++j){
  32. f[j]=(f[j-1]*2)%p;
  33. sum=(sum+f[j])%p;
  34. }
  35. for(int j=limit+1;j<=n;++j){
  36. f[j]=sum;
  37. sum=((sum-f[j-limit])%p+p)%p;
  38. sum=(sum+f[j])%p;
  39. }
  40. ans=(ans+f[n])%p;
  41. }
  42. printf("%lld\n",ans);
  43. return 0;
  44. }

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

发表评论

表情:
评论列表 (有 0 条评论,206人围观)

还没有评论,来说两句吧...

相关阅读

    相关 cf 1009E

    如何看待某cf2000分选手不会一道tag1900的题? 难。 考虑每段距离的贡献, a\[i\]出现在位置j上,当且仅当j-i休息,并且中间的都不是休息的。