HDU--1257 longest increasing subsequence (DP)

Address: http://acm.hdu.edu.cn/showproblem.php?pid=1257

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 3e4+10;
typedef long long ll;
ll a[maxn];
ll dp[maxn];
int main ()
{
    ll n;
    while(cin>>n)
    {
        
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i =0 ; i< n;i++)
        dp[i]=1;
    ll maxx=-1;
    for(int i = 1;i<n;i++)
    {
        for(int j = 0 ; j < i ; j++)
        {
            if(a[i]>a[j])
            {
                dp [i] = max (dp [i], dp [j] + 1 );  // Still thinking, choose or not choose 
            }  
        }
        maxx=max(dp[i],maxx);
    }
    cout<<maxx<<endl;}
}

 

Guess you like

Origin www.cnblogs.com/liyexin/p/12683109.html