codeforces 603 A
题目大意:给你一个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的更多相关文章
- [Codeforces] #603 (Div. 2) A-E题解
[Codeforces]1263A Sweet Problem [Codeforces]1263B PIN Code [Codeforces]1263C Everyone is a Winner! [ ...
- CTGU_训练实录
前言 之前做题都没有感觉,慢慢出去比赛后,打Codeforces,看别的人博客,知乎上的讨论,慢慢的对算法有一些自己的思考.特写是最近看知乎上别人说的Dijkstra利用水流去理解,LCA的学习,感觉 ...
- 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 ...
- 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 ...
- 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, ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- core EFCore 开始尝试
准备工作: 工程:core + console 引用包: Install-Package Microsoft.EntityFrameworkCore Install-Package Microsoft ...
- 七、Kafka 用户日志上报实时统计之编码实践
一.数据生产实现 1.配置数据生产模块 项目基础配置所包含的内容,如下所示: •项目工程的文件配置 •集群连接信息配置 •开发演示 2.实现 Flume 到 Kafka 模块 实现 Flume 到 K ...
- 用pip install升级已安装的包的附加包, 以tabulate包为例
用pip install升级已安装的附加包, 以tabulate包为例 去pypi官网查看tabulate包的介绍, 发现tabulate 0.7.6才开始支持宽字符的美化打印. 而且还需要安装它的附 ...
- 关于node的setTimeout的延时最大限制
node的setTimeout有最大值限制,最大值为2^31-1.一旦超过了最大值,其效果就跟延时值为0的情况一样,也就是马上执行.chrome测试并未发现该问题,解决方案如下,重写setTimeou ...
- soj1046. Plane Spotting
1046. Plane Spotting Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Craig is fond o ...
- IFrame跨域处理方法-Javascript
在漫长的前端开发旅途上,无可避免的会接触到ajax,而且一般情况下都是用在同一域下的ajax请求:但是如果请求是发生在不同的域下,请求就无法执行,并且会抛出异常提示不允许跨域请求,目前我没有找到明确的 ...
- [转]ubuntu16.04~qt 5.8无法输入中文
编译fcitx-qt需要cmake,安装cmake命令,如果已经安装,请略过. sudo apt-get install cmake 安装 fcitx-libs-dev sudo apt-get in ...
- 08 Packages 包
Packages Standard library Other packages Sub-repositories Community Standard library Name Synopsis ...
- 获取SQL Server的版本信息
微软 SQL Server 版本号 产品名称 发行日期 主版本号 正式版 SP1 SP2 SP3 SP4 SQL Server 2016 2016.06.01 13.00.1601.5 13.00.1 ...
- mysql数据库查找类型不匹配
无意中看到10级学长的博客,提到了mysql数据库类型查找不匹配的问题,博客地址是:卢俊达 . 数据库中建表中会对每个属性进行类型划分,然后在查找数据库select时: MySQL 的文档 (Type ...