题目大意:给你一个长度为n的数组长度,求环形道路的最长上升子序列或最长下降子序列
题目思路:直接dp做一下就好了
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 205;
int n,a[maxn],dp1[maxn],dp2[maxn];
int main(){
while(~scanf("%d",&n)&&n){
memset(dp1,0,sizeof(dp1));
memset(dp2,0,sizeof(dp2));
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
a[i+n] = a[i];
}
int maxx = -1;
for(int i = 1;i <= 2*n-1;i++){
if(a[i] > a[i+1]) dp1[i+1] = dp1[i]+1;
if(a[i] < a[i+1]) dp2[i+1] = dp2[i]+1;
maxx = max(maxx,max(dp1[i+1],dp2[i+1]));
}
printf("%d\n",maxx);
}
return 0;
}