Luo Gu P1091 chorus queue

It referred to the Wang Jian, the Wudeng to heart - "Fate / stay night"

Topic: https://www.luogu.org/problem/P1091

This question should be, is a more classic, relatively simple dynamic regulatory issues.

Its nature is also evident template -

It is the longest sequence rise

So it should be seen that dynamic regulation of T1 <T2 <... <Ti> Ti + 1> ...> Tk know it

Well, this question should also be considered a little bit out of the least, it means that the most left,

So LIS real hammer:

As long as each point to the left, led by the decline of the longest sub-sequence and its rise to the right of the longest sequences are seeking out, and then added that it was leaving the center of the largest number.

Well, on the code:

#include<bits/stdc++.h>
using namespace std;
int n,maxn=0;
int a[105];
int f[105][4];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) 
    {
        scanf("%d",&a[i]);
        f[i][1]=f[i][2]=1;
    }
    
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            if(a[i]>a[j]&&f[j][1]>=f[i][1])
            {
                f[i][1]=f[j][1]+1;
            } 
        }
    }
    for(int i=n-1;i>=1;i--)
    {
        for(int j=i+1;j<=n;j++) 
        { 
            IF (A [I]> A [J] && F [J] [ 2 ]> = F [I] [ 2 ]) 
            { 
                F [I] [ 2 ] = F [J] [ 2 ] + . 1 ; 
            } 
        } 
    } // find the longest sequence rise and maximum decrease sequences 
    
    for ( int I = . 1 ; I <= n-; I ++ ) 
    { 
        F [I] [ . 3 ] = F [I] [ . 1 ] + F [I ] [ 2 ] - . 1 ;
         IF (F [I] [ . 3 ]> MAXN) 
            MAXN = F [I] [ . 3]; // This is the number of reserved 
    } 
    the printf ( " % D \ n- " , n--MAXN); // n-number-MAXN is kicked off 
    return  0 ; 
}

I started output is maxn, the result is two points over the

Again--

Details determine success or failure ah! ! ! ! !

Guess you like

Origin www.cnblogs.com/fjnhyzcrx-Mayuri/p/11525133.html