Cheap to buy (LIS program statistics)

Meaning of the questions: https://www.luogu.com.cn/problem/P1108

If the two numbers are identical number of columns composed, then we say that two identical columns.

Program to find the number of the longest sequence decline.


Solution to a problem from  wjyyy great God.

In dp process, f array stored is the length of the longest sequence decline, f subscript f array i is the i end means, the longest sequence drop data (except the last one outside) has been lost, therefore no longer applied when determining whether the program numbers together.

We look from scratch,

  1. If the number of the first number with another number of columns of a first row of the same number, it can now be determined they are equal, i.e., one can delete (processing code is T [J] = 0 ). When connected to a different number on its back, and they can be determined that the two series, which does not affect each other. Because the two columns can be transferred from the equal number of columns from
  2. If the number of the first number with another number of columns of a row different from the first number, so they are not equal, and no matter what add back, not equal, i.e. not deleted, then continue according to the conventional judgment.

From the above two points, we have deleted the repeated, this prevents double counting.

#include <bits / STDC ++ H.>
 the using  namespace STD;
 #define max (A, B) (A> B A:? B)
 int A [ 5009 ], F [ 5009 ], T [ 5009 ];
 // A [ i] is subject to stock prices, f [i] is the length of the longest day i
 // T [i] is the end of the program i 
int main () 
{ 
    int n-, MAXN = 0 ; 
    CIN >> n-;
     for ( int I = . 1 ; I <= n-; I ++) CIN >> A [I], F [I] = . 1 ;
     for ( int I = . 1 ; I <= n-; I ++ ) 
    { 
        for( Int J = . 1 ; J <I; J ++ ) 
        { 
            IF (A [I] < A [J]) 
                F [I] = max (F [I], F [J] + . 1 ); 
        } // now is longest seek normal decline sequence 
        MAXN = max (MAXN, F [I]); // note the length of the longest 
        for ( int J = . 1 ; J <I; J ++ ) 
        { 
            IF (F [I] == F [J] && A [I] == A [J]) // same length and the number of columns of identical 
                T [J] = 0 ;
             the else  IF (F [I] == F [J] + . 1 && A [I] <A [J]) // can be connected in front of the
                t[i]+=t[j]; 
        }
        if(!t[i])    t[i]=1;//为了后面的数转移 
    }    
    int ans=0;
    for(int i=1;i<=n;i++)
        if(f[i]==maxn)    ans+=t[i];
    cout<<maxn<<" "<<ans;
} 

 

Guess you like

Origin www.cnblogs.com/iss-ue/p/12501951.html