题目大意:给你一个0,1串, 你可以反转一段连续的区间,问你最长的合法子串是多长, 合法字串相邻的两个不能相同。

思路:dp[ i ][ k ][ j ] 表示到第 i 个字符, 处于k这种状态, k = 0 表示 没有开始反转 k = 1 表示在反转的过程中, k = 2 表示反转结束, 最后一个字符为 j 的最大子序列。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> > using namespace std; const int N = 2e5 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; char s[N];
int dp[N][][], n;
int main() {
memset(dp, , sizeof(dp));
scanf("%d%s", &n, s + );
dp[][][] = dp[][][] = ;
int ans = ;
for(int i = ; i <= n; i++) {
for(int k = ; k < ; k++) {
int x = s[i] - '';
if(k == ) {
dp[i][][x] = dp[i - ][][x];
dp[i][][x ^ ] = dp[i - ][][x ^ ];
dp[i][][x] = max(dp[i][][x], dp[i - ][][x ^ ] + );
} else if(k == ) {
x ^= ;
dp[i][][x] = dp[i - ][][x];
dp[i][][x ^ ] = dp[i - ][][x ^ ];
dp[i][][x] = max(dp[i][][x], dp[i - ][][x ^ ] + );
dp[i][][x] = max(dp[i][][x], dp[i - ][][x ^ ] + );
} else if(k == ) {
dp[i][][x] = dp[i - ][][x];
dp[i][][x ^ ] = dp[i - ][][x ^ ];
dp[i][][x] = max(dp[i][][x], dp[i - ][][x ^ ] + );
dp[i][][x] = max(dp[i][][x], dp[i - ][][x ^ ] + );
}
ans = max(ans, dp[i][k][]);
ans = max(ans, dp[i][k][]);
}
}
printf("%d\n", ans);
return ;
}
/*
*/

codeforces 603 A的更多相关文章

  1. [Codeforces] #603 (Div. 2) A-E题解

    [Codeforces]1263A Sweet Problem [Codeforces]1263B PIN Code [Codeforces]1263C Everyone is a Winner! [ ...

  2. CTGU_训练实录

    前言 之前做题都没有感觉,慢慢出去比赛后,打Codeforces,看别的人博客,知乎上的讨论,慢慢的对算法有一些自己的思考.特写是最近看知乎上别人说的Dijkstra利用水流去理解,LCA的学习,感觉 ...

  3. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  4. Codeforces Round #603 (Div. 2) E. Editor 线段树

    E. Editor The development of a text editor is a hard problem. You need to implement an extra module ...

  5. Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

    D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...

  6. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  7. Codeforces Round #603 (Div. 2) D. Secret Passwords(并查集)

    链接: https://codeforces.com/contest/1263/problem/D 题意: One unknown hacker wants to get the admin's pa ...

  8. Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)

    链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...

  9. Codeforces Round #603 (Div. 2) B. PIN Codes

    链接: https://codeforces.com/contest/1263/problem/B 题意: A PIN code is a string that consists of exactl ...

随机推荐

  1. [转] malloc基本实现

    任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...

  2. [整理]C语言中字符常量与ASCII码

    所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示.而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\n等,就称为转义字符,因为 ...

  3. subtle:有趣的伪平铺式窗口管理器

    Author:吴吉庆 email: jiqingwu@gmail.com home:http://hi.baidu.com/jiqing0925 create:2011-02-19 update:20 ...

  4. 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块

    [题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...

  5. 38、使用IO流进行文件拷贝

    使用IO流进行文件拷贝 需求:在项目的根目录里面创建一个java.txt的文件,然后将这个文件拷贝到file文件夹里面并且重命名为good.txt文件先以流的方式将java.txt文件读取到内存中,然 ...

  6. PHP简单爬虫 基于QueryList采集库 和 ezsql数据库操作类

    QueryList是一个基于phpQuery的PHP通用列表采集类,得益于phpQuery,让使用QueryList几乎没有任何学习成本,只要会CSS3选择器就可以轻松使用QueryList了,它让P ...

  7. Vue 项目添加 promise polyfill

    1. 安装依赖 npm install es6-promise --save 2. 在 main.js 上面引入: import 'es6-promise/auto'

  8. 【codeforces】【比赛题解】#868 CF Round #438 (Div.1+Div.2)

    这次是Div.1+Div.2,所以有7题. 因为时间较早,而且正好赶上训练,所以机房开黑做. 然而我们都只做了3题.:(. 链接. [A]声控解锁 题意: Arkady的宠物狗Mu-mu有一只手机.它 ...

  9. ubuntu16.04 eclipse+pydev 配置

    参考:http://blog.csdn.net/bluish_white/article/details/56509446,http://blog.csdn.net/qing101hua/articl ...

  10. windows环境cmd下执行jar

    项目目录结构 一,在pom.xml文件里添加配置 <build> <plugins> <plugin> <groupId>org.apache.mave ...