Diworth Theorem

Diworth Theorem

A sequence number of the minimum number of divided sub-sequence is equal to the maximum drop increase the length of the sub-sequence.

A sequence number of divisions increase the minimum number of sequences is equal to the length of the longest sequence of drops.

Both before and after the sentence in the partial order relation each other.

example:

Description

LIS is one of the most classic dynamic programming foundation problems. If certain conditions are required to meet a rise in the longest sequence, can you solve it?
Given a sequence length of integer N, the requested increase its longest sub-sequence comprises K elements.
For example: the length of the sequence 6 <2,7,3,4,8,5>, which increased the longest sub-sequence <2,3,4,5>, but must include the restriction if the second element then rise to meet this requirement of the longest sub-sequence can only be <2,7,8> a.

Input

The first two acts of integers N, K, as described above.

Followed by N integers, described in a sequence.

For all data satisfies \ (0 <n <= 200000,0 <k <= n \)

Output

Please output two integers, i.e. the K-th element contains the longest sequence length increase.

\(Sample Input\)

8 6

65 158 170 299 300 155 207 389

\(Sample Output\)

4

Theorem can be converted using the Diworth issue for the sake of the longest rising sequence, sets up a bit on it ...

Look at the data range, do not fight violence. With the longest rise with lower_bound optimized sequence on the line ...

CODE:

#include<bits/stdc++.h>
using namespace std;
int a[40001];
int len=1;
int dp[40001];
int main()
{
    int tot;
    cin>>tot;
    for(int i=1;i<=tot;i++)
        cin>>a[i];
    tot--;
    dp[1]=a[1];
    for(int i=2;i<=tot;i++)
    {
        if(a[i]>dp[len])dp[++len]=a[i];
        else *lower_bound(dp+1,dp+1+len,a[i])=a[i];
    }
    cout<<len<<endl;

    return 0;
}

Guess you like

Origin www.cnblogs.com/moyujiang/p/11626886.html