895. 最长上升子序列

LIS:最长上升子序列问题,经典dp问题。

状态用一维来表示f(i)

#include<iostream>
using namespace std;

const int N = 1010;

int f[N];
int s[N];
int n, res;

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i ++){
        cin >> s[i];
        int mx = 0;
        for(int j = 0; j < i; j ++)
            if(s[j] < s[i]) mx = max(mx, f[j]);
        f[i] = mx + 1;
        
        res = max(f[i], res);
    }
    
    cout << res;
    
    return 0;
}
posted @ 2020-09-05 20:30  yys_c  阅读(114)  评论(0编辑  收藏  举报