题目大意:给你一个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. 二维数组和指针(C语言)

    二维数组和指针 二维数组和指针1.二维数组和数组元素的地址若有以下定义:int *p, a[3][4]; 1)二维数组a由若干个一维数组组成在C语言中定义的二维数组实际上是一个一维数组,这个一维数组的 ...

  2. MySQL报错】ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 39.

    之前在centos6.4系统安装的是自带的mysql 5.1版本,后来升级到了5.6版本,执行以下命令报错 在网上查找原因说说因为升级不当导致,执行以下命令即可正常执行命令 mysql_upgrade ...

  3. Swing教程

    //用多线程刷新状态 new Thread(new Runnable(){ @Override public void run() { try { for(int i=0;i<1000;i++) ...

  4. bzoj 2726 [SDOI2012]任务安排(斜率DP+CDQ分治)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2726 [题意] 将n个任务划分成若干个块,每一组Mi任务花费代价(T+sigma{ t ...

  5. [译] 用HTML5捕获音频和视频

    原文地址:http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 概述 有了HTML5,我们就可以在不借助Flash或者Silverlig ...

  6. Q - Phalanx

    题目链接:https://vjudge.net/contest/68966#problem/Q 分析:这里的对称并不是指的是关于原矩阵(也就是最大的那一个)主对角线对称,而是对于每一个小的矩阵来说,当 ...

  7. [转]google gflags 库完全使用

    简单介绍 gflags 是 google 开源的用于处理命令行参数的项目. 安装编译 项目主页:gflags ➜ ~ git clone https://github.com/gflags/gflag ...

  8. 使用vue的一些经验

    虽然说VUE是数据驱动视图的框架,但有时候不得不获取DOM来获得一些样式属性,做一些操作,这时候就需要VUE获取DOM对象的方法. vue获取DOM对象的方法: 如果是操作组件内部的DOM,可以通过给 ...

  9. Libheap:一款用于分析Glibc堆结构的GDB调试工具

    Libheap是一个用于在Linux平台上分析glibc堆结构的GDB调试脚本,使用Python语言编写.         安装 Glibc安装 尽管Libheap不要求glibc使用GDB调试支持和 ...

  10. Django 1.10中文文档-模型参考

    模型字段 本文档包含了Django提供的全部模型 Field 包括 字段选项 和 字段类型 的API参考. 参见 如果内建的字段不能满足你的需求, 你可以蚕食 django-localflavor ( ...