题目描述

咳咳,懒得复制了上面是两张图:)

解题思路

这题是一道很好的题,感觉之前做过,一开始手推状态找规律,可以用状压但是没想到

借鉴了一下大佬的dp

modify数组用以累加新增的状态数

dp数组表示前i列第j个连通块,a,b表示该列的状态,转移方程见代码

下面就是美丽的代码了

AC Code

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define P (LL)(998244353) typedef long long LL;
typedef long double ld;
typedef unsigned long long ULL; using namespace std; const int MAXN = + ;
const int MAXK = MAXN << ;
int dp[MAXN][MAXK][][];
int modify[][][][];
void pre() {
modify[][][][] = ; modify[][][][] = ; modify[][][][] = ; modify[][][][] = ;
modify[][][][] = ; modify[][][][] = ; modify[][][][] = ; modify[][][][] = ;
modify[][][][] = ; modify[][][][] = ; modify[][][][] = ; modify[][][][] = ;
modify[][][][] = ; modify[][][][] = ; modify[][][][] = ; modify[][][][] = ;
}
int main() {
int n , k;
cin>>n>>k;
pre();
dp[][][][] = dp[][][][] = ;
dp[][][][] = dp[][][][] = ; for(int i = ; i <= n; i++)
for(int j = ; j <= k; j++)
for(int a = ; a < ; a++)
for(int b = ; b < ; b++)
for(int A = ; A < ; A++)
for(int B = ; B < ; B++) {
int block = modify[A][B][a][b];
if(j >= block) dp[i][j][a][b] = (dp[i][j][a][b] + dp[i - ][j - block][A][B]) % P;
}
int ans = ;
for(int A = ; A < ; A++)
for(int B = ; B < ; B++)
ans = (ans + dp[n][k][A][B]) % P;
cout<<ans;
return ;
}

CF1051D Bicolorings的更多相关文章

  1. CF1051D Bicolorings dp

    水题一道 $f[i][j][S]$表示$2 * i$的矩形,有$j$个联通块,某尾状态为$S$ 然后转移就行了... #include <vector> #include <cstd ...

  2. CF1051D Bicolorings 递推

    考试T2,随便推一推就好了~ code: #include <bits/stdc++.h> #define N 1015 #define mod 998244353 #define ll ...

  3. codeforces 1051 D. Bicolorings (DP)

    D. Bicolorings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces 1051 D.Bicolorings(DP)

    Codeforces 1051 D.Bicolorings 题意:一个2×n的方格纸,用黑白给格子涂色,要求分出k个连通块,求方案数. 思路:用0,1表示黑白,则第i列可以涂00,01,10,11,( ...

  5. CodeForces - 1051D Bicolorings(DP)

    题目链接:http://codeforces.com/problemset/problem/1051/D 看了大佬的题解后觉着是简单的dp,咋自己做就做不来呢. 大佬的题解:https://www.c ...

  6. cf1051d 简单的状态压缩dp

    /* 给定一个二行n列的格子,在里面填黑白色,要求通过黑白色将格子分为k块 请问有多少种填色方式 dp[j][k][0,1,2,3] 填到第j列,有k块,第j列的颜色, */ #include< ...

  7. D. Bicolorings

    传送门 [http://codeforces.com/contest/1051/problem/D] 题意 相当于有个2列n行得棋盘,棋盘上的格子只能是黑或者白,问你联通块为k得方案数有多少,结果对 ...

  8. Educational Codeforces Round 51 D. Bicolorings(dp)

    https://codeforces.com/contest/1051/problem/D 题意 一个2*n的矩阵,你可以用黑白格子去填充他,求联通块数目等于k的方案数,答案%998244353. 思 ...

  9. 2018.09.21 codeforces1051D. Bicolorings(线性dp)

    传送门 sb线性DP. f[i][j][0/1/2/3]f[i][j][0/1/2/3]f[i][j][0/1/2/3]表示前i列j个连通块且第i列状态为00/01/10/11时的方案总数. 这个显然 ...

随机推荐

  1. LeetCode 1102. Path With Maximum Minimum Value

    原题链接在这里:https://leetcode.com/problems/path-with-maximum-minimum-value/ 题目: Given a matrix of integer ...

  2. 数据库 Hash Join的定义,原理,算法,成本,模式和位图

    Hash Join只能用于相等连接,且只能在CBO优化器模式下.相对于nested loop join,hash join更适合处理大型结果集       Hash Join的执行计划第1个是hash ...

  3. WinDbg常用命令系列---显示数字格式化.formats

    .formats (Show Number Formats) .formats命令在当前线程和进程的上下文中计算表达式或符号,并以多种数字格式显示它. .formats expression 参数: ...

  4. openjdk k8s port-forward 连接容器jmx服务

    jmx 是java 自带的,如果需要使用我们只需要添加对应的配置即可,以下演示docker 集成jmx 使用kompose 生成k8s 的部署文件,使用port-forward 进行连接,所以java ...

  5. circus && web comsole docker-compose 独立部署

    问题的根本原因是web console 的bug(实际上还是python 对于依赖版本出来不明确) circus 进程docker 镜像 dockerfile FROM python:slim-str ...

  6. box-sizing 盒子模型

    一.概念 ①外加模式: box-sizing: content-box 这是由 CSS2.1 规定的宽度高度行为.宽度和高度分别应用到元素的内容,在宽度和高度之外绘制元素的内边距,即宽和高不包括内边距 ...

  7. windows 获取时间戳

    Windows 批处理时间戳 1.时间戳格式: 取年份: echo %date:~,% 取月份: echo %date:~,% 取日期: echo %date:~,% 取星期: echo %date: ...

  8. Codevs 3122 奶牛代理商 VIII(状压DP)

    3122 奶牛代理商 VIII 时间限制: 3 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 小徐是USACO中国区的奶牛代理商,专门出售质优 ...

  9. CF1098E Fedya the Potter

    CF1098E Fedya the Potter 题意:有一个序列\(A\). 对所有\(1\leq l\leq r\leq |A|\),将\(\gcd_{i=l}^{r}A_i\)加入\(B\)中. ...

  10. Educational Codeforces Round 67

    Educational Codeforces Round 67 CF1187B Letters Shop 二分 https://codeforces.com/contest/1187/submissi ...