泰州网站设计公司,怎么做cms网站,域名注册后网站建设,武威市网站建设传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你一个长度为nnn的只包含1,21,21,2的序列aaa#xff0c;你可以至多翻转一段区间#xff0c;求翻转之后最长非递减子序列是多长。
思路#xff1a;
考虑如果翻转的话#xff0c;翻转的子区间肯定是22…传送门
文章目录题意思路题意
给你一个长度为nnn的只包含1,21,21,2的序列aaa你可以至多翻转一段区间求翻转之后最长非递减子序列是多长。
思路
考虑如果翻转的话翻转的子区间肯定是222211112222111122221111这种类型的再加上前面可能有111后面可能有222那么我们求的最长子序列的类型一定是类似于111222111222111222111222111222111222所以我们只需要求一个类似于这种的序列最长是多少即可。 定义aaa为111111111类型的最长长度bbb为112211221122类型的最长长度ccc为112211112211112211类型的最长长度ddd为112211221122112211221122类型的最长长度。 如果当前为111那么aa1,cmax(c1,b1)aa1,cmax(c1,b1)aa1,cmax(c1,b1)。 如果当前为222那么bmax(b1,a1),dmax(d1,c1)bmax(b1,a1),dmax(d1,c1)bmax(b1,a1),dmax(d1,c1)。 直接输入的时候转移即可。
// Problem: C. A Twisty Movement
// Contest: Codeforces - Codeforces Round #462 (Div. 2)
// URL: https://codeforces.com/contest/934/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].ltr[u].r1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N1000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n;int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);int x,y,z,w;xyzw0;scanf(%d,n);for(int i1;in;i) {int now; scanf(%d,now);if(now1) {xx1;zmax(z1,y1);}else {ymax(y1,x1);wmax(w1,z1);}}printf(%d\n,max(z,w));return 0;
}
/**/