其他分享
首页 > 其他分享> > 【DP】动态规划专题

【DP】动态规划专题

作者:互联网

895. 最长上升子序列

image

#include <iostream>

using namespace std;

const int N = 1010;

int n;
int a[N], f[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
    
    for(int i = 1; i <= n; i ++ )
    {
        f[i] = 1;
        for(int j = 1; j < i; j ++ )
        {
            if(a[j] < a[i])
                f[i] = max(f[i], f[j] + 1);
        }
    }   
    int res = 0;
    for(int i = 1; i <= n; i ++ ) res = max(res, f[i]);
    printf("%d\n", res);
    
    return 0;
}

标签:std,专题,const,895,int,main,1010,DP,动态
来源: https://www.cnblogs.com/Tshaxz/p/16169533.html