HDU ACM 4512 Story--Perfect formation I->lcis the longest common increment subsequence

Source: Internet
Author: User

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

Related Article

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.