题目大意:给你一个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. jvm如何判断对象是否可以被回收

    内容基本来自周志明 深入理解Java虚拟机 第二版 第三章 .这本书还可以,不过好像也没什么其他中文的关于jvm比较好的书了 jvm要做垃圾回收时,首先要判断一个对象是否还有可能被使用.那么如何判断一 ...

  2. 在升级Windows 8.1后,桌面的右下角显示"SecureBoot未正确配置"

    原地址为:http://ask.zol.com.cn/q/201881.html 第一种模式BIOS: 在将Secure Boot设置为Enabled后,Secure Boot Status依然为关闭 ...

  3. 翻译: 星球生成 II

    翻译: 星球生成 II 本文翻译自Planet Generation - Part II 译者: FreeBlues 以下为译文: 概述 在前一章 我解释了如何为星球创建一个几何球体. 在本文中, 我 ...

  4. List(JDK1.7)(1)

    java.util包. 与Set不同, List允许重复的元素.即 e1.equals(e2). 部分方法定义 int size(); 返回列表中元素的个数,如果超过Integer.MAX_VALUE ...

  5. ASP.NET根据IP获取省市地址

    1.在网站的跟路径下面添加 QQWry.dat 文件,这个文件是IP数据库文件 2.添加以下一个类 IPScanner     C# 代码   复制 public class IPScanner { ...

  6. TED_Topic6:How to raise a black son in America

    By Clint Smith As kids, we all get advice from parents and teachers that seems strange, even confusi ...

  7. Nginx配置location及rewrite规则

    Nginx配置location及rewrite规则 示例: location  = / {   # 精确匹配 / ,主机名后面不能带任何字符串   [ configuration A ] } loca ...

  8. ASP.NET 应用生命周期19个事件简介

    下面是请求管道中的19个事件. (1)BeginRequest: 开始处理请求 (2)AuthenticateRequest授权验证请求,获取用户授权信息 (3):PostAuthenticateRe ...

  9. meterpreter使用

    1.基本命令 background:将meterpreter终端隐藏在后台 sessions:查看已经成功获取的会话,想继续与某会话进行交互使用sessions –i quit:直接关闭当前meter ...

  10. 20155303 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20155303 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 (一)使用JDK编译.运行简单的java程序 命令行下的程序开发 步骤一(新建文件夹): ...