[CF991D]Bishwock_状压dp
Bishwock
题目链接:http://codeforces.com/problemset/problem/991/D
数据范围:略。
题解:
一眼题。
首先,每个$L$最多只占用两列,而且行数特别少,我们考虑状态压缩。
即$f_{i, S}$表示前$i$列,第$j$列的状态为$S$时,前$j$最多能放多少个。
随便弄一弄就好了。
代码:
#include <bits/stdc++.h>
#define setIO(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define N 100010
using namespace std;
int f[N][1 << 4], dic[4];
char s[2][N];
int main() {
// setIO("a");
scanf("%s%s", s[0] + 1, s[1] + 1);
int n = strlen(s[0] + 1);
int all = (1 << 4) - 1;
for (int i = 0; i < 4; i ++ ) {
dic[i] = all - (1 << i);
}
for (int i = 2; i <= n; i ++ ) {
int mdl = 0;
if (s[0][i - 1] == 'X') {
mdl += 1;
}
if (s[1][i - 1] == 'X') {
mdl += 2;
}
if (s[0][i] == 'X') {
mdl += 4;
}
if (s[1][i] == 'X') {
mdl += 8;
}
// cout << mdl << endl ;
for (int s1 = 0; s1 < (1 << 2); s1 ++ ) {
for (int s2 = 0; s2 < (1 << 2); s2 ++ ) {
// i -> s1, i - 1 -> s2
int tmp = s2 + (s1 << 2), re = all - tmp;
if ((tmp & mdl) == mdl) {
f[i][s1] = max(f[i][s1], f[i - 1][s2]);
for (int k = 0; k < 4; k ++ ) {
if ((dic[k] & re) == dic[k]) {
int x = s2;
if (dic[k] & 1) {
x ++ ;
}
if (dic[k] & 2) {
x += 2;
}
f[i][s1] = max(f[i][s1], f[i - 1][x] + 1);
}
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= all; i ++ ) {
ans = max(ans, f[n][i]);
}
cout << ans << endl ;
fclose(stdin), fclose(stdout);
return 0;
}
小结:一定要想明白状态再转移。
[CF991D]Bishwock_状压dp的更多相关文章
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
- [NOIP2016]愤怒的小鸟 D2 T3 状压DP
[NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...
- 【BZOJ2073】[POI2004]PRZ 状压DP
[BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...
- bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)
数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
[BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...
随机推荐
- Start Failed, Internal error: recovering IDE to the working state after the critical startup error
Start Failed, Internal error: recovering IDE to the working state after the critical startup error F ...
- .netcore signalR 实时消息推送
服务器端引入包 Install-Package Microsoft.AspNetCore.SignalR客户端引入包 npm install @aspnet/signalr <template ...
- Ubuntu 14.04 下安装redis后运行redis-cli 报出redis Connection refused错误【已解决】
在运行redis-cli运行后爆出错误,看了网上的都没有用例如:改ip,注释bind 127.0.0.1,或者是先运行./redis-server redis.conf,都没有用 只需要: 找到red ...
- jquer属性 offset、position、scrollTop
尺寸操作 1.获取宽高 a) jq对象.height/width () :只有获取高度/宽度 尺寸,不包括padding和margin 和 border 2.设置宽度 ...
- 检测ip代理有效性
转载及总结 转载:https://xw.qq.com/amphtml/20190428A05ZS200 1.telnet 方法 经过测试,会看到存在以下问题: 即使一些代理商能够用telnet测试过关 ...
- Redis集群都有哪些模式
前言: 一,为什么要使用redis 1,解决应用服务器的cpu和内存压力 2,减少io的读操作,减轻io的压力 3,关系型数据库扩展性不强,难以改变表的结构 二,优点 1,nosql数据库没有关联关系 ...
- OLAP、OLTP的介绍CBO/RBO
OLTP与OLAP的介绍 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical ...
- BUUCTF-writeup
Reverse RSA 使用openssl模块 rsa -pubin -text -modulus -in pub.key得到n值,在 factordb.com上分解大素数得到p,q值,脚本生成pri ...
- error C2086: “int WINGDIAPI”: 重定义
1>------ 已启动生成: 项目: OSG_3_1_osgViewer应用基础, 配置: Debug x64 ------1>cl : 命令行 warning D9002: 忽略未知选 ...
- 独立的js文件中不能使用EL表达式取值
在独立的js文件中写了一个EL表达式取值,发现没有取到值,原因在于不能在独立的js文件中使用EL表达式,可以在jsp页面定义全局变量,然后在js文件中引用