Jzoj3176 Spider-Man

Source: Internet
Author: User
Tags min

There are a lot of superheroes in the world: Batman, Spider-Man, Superman, people who can't write names, and so on. Among them was one called kickass. Today he wanted to imitate Spider-Man, so he chose a row of tall buildings to jump.

Specifically, he chose a column of n buildings, numbered from left to right, from 1 to N. At first he was in the first building of the K-tower. Unfortunately, kickass ability is very limited, can only jump to the left or right adjacent high-rise, and he must jump to the height of the building should not be greater than he is now in the height of the building. Kickass didn't want to look like a slag to himself, so he put a trampoline on top of some tall buildings and jumped from them to any other tall building, no matter where or how high the tall building was going to jump to.

Your mission is to find the number of tall buildings that kickass can jump to at the top of the K-tower. If kickass jumps to a tall building more than once, we will only count it once. And even if Kickass did not jump, the K-building would be counted as the answer.

Brush water problem is beneficial to physical and mental health

Very simple diagram of the topic, Tarjan to run the Dag after the longest road is good, the code basically does not have to be moved directly over to be able to use

#pragma GCC optimize ("O3") #pragma g++ optimize ("O3") #include <vector> #include <stdio.h> #include <
string.h> #include <algorithm> #define N 300010 using namespace std; struct edge{int v,nt;} G[N*3];
Char S[n];
int h[n],dfn[n],low[n],col[n],f[n],n,m,cnt=0; Vector<int> G2[n];
int st[n],top=0,clk=0,col,sz[n],v[n]; 
	inline void adj (int x,int y) {g[++cnt]= (Edge) {y,h[x]}; h[x]=cnt;} void Tarjan (int x) {dfn[x]=low[x]=++clk;
	St[++top]=x;
		for (int v,i=h[x];i;i=g[i].nt) if (!dfn[v=g[i].v]) {Tarjan (v); Low[x]=min (Low[x],low[v]);
	} else if (!col[v]) low[x]=min (Low[x],dfn[v]);
		if (Low[x]==dfn[x]) {++col;
	do {col[st[top]]=col; sz[col]++;} while (st[top--]!=x);
	}} int dp (int x) {if (~f[x]) return f[x]; f[x]=0;
	for (int i=0,z=g2[x].size (); i<z;++i) F[x]=max (F[X],DP (G2[x][i])); F[X]+=SZ[X];
return f[x];
	} int main () {scanf ("%d%d", &n,&m); for (int i=1;i<=n;++i) scanf ("%d", v+i);
	scanf ("%s", s+1);
		for (int i=1;i<=n;++i) {adj (n+1,i); if (S[i]= = ' T ') adj (i,n+1);
			else{if (i>1&&v[i]>=v[i-1]) adj (i,i-1);
		if (i<n&&v[i]>=v[i+1]) adj (i,i+1); }} memset (f,-1,sizeof f);
	++n; for (int i=1;i<=n;++i) if (!dfn[i]) Tarjan (i);
	sz[col[n]]--;
	for (int i=1;i<=n;++i) for (int j=h[i];j;j=g[j].nt) if (COL[I]!=COL[G[J].V]) g2[col[i]].push_back (COL[G[J].V]);
printf ("%d\n", DP (Col[m])); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.