HDU--1257最長増加サブシーケンス(DP)

アドレス: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)
    { 
        
    forint i = 0 ; i <n; i ++ 
        cin >> a [i];
    forint i = 0 ; i <n; i ++
        dp [i] = 1 ; 
    ll maxx = -1 ;
     forint i = 1 ; i <n; i ++ 
    { 
        forint j = 0 ; j <i; j ++ 
        { 
            if(a [i]> a [j])
            { 
                dp [i] = max(dp [i]、dp [j] + 1);  // 引き続き考えて、選択するかしないかを選択する
            }  
        } 
        maxx = max(dp [i]、maxx); 
    } 
    cout << maxx << endl;}
}

 

おすすめ

転載: www.cnblogs.com/liyexin/p/12683109.html