Analysis: The longest public increment sub-sequence, the data is stored in reverse, for the pros and cons of two sets of data LCIs. In addition notice the condition of the boundary to judge. And if the new queue is taken out there are odd numbers of people or even a few people to judge alone.
#include <iostream>using namespace std #define MAX (a) > (b) ( A):(b)) int dp[202];int a[202];int b[202];int lcis (int n) {int I,j,maxlen,ans;memset (dp,0,sizeof (DP)); Ans=0;for (i=1;i <=n;i++) {maxlen=0;for (j=1;j<=n-i+1;j++) //j<=n-i+1 guarantees a maximum of one person {if (A[i]>b[j]) Maxlen=max in the middle (MAXLEN,DP [j]); else if (A[i]==b[j]) dp[j]=maxlen+1;if (i<n-j+1) //Whether overlapping Ans=max (ans,dp[j]*2); Elseans=max (ans,dp[j]*2-1);}} return ans;} int main () {int T,n,i;cin>>t;while (t--) {cin>>n;for (i=1;i<=n;i++) {cin>>a[i];b[n-i+1]=a[i]; Reverse storage}cout<<lcis (n) <<endl;} return 0;}
HDU ACM 4512 Story--Perfect formation I->lcis the longest common increment subsequence