LIS模板题(Longest Ordered Subsequence)

LIS模板题(Longest Ordered Subsequence)

poj-2533

给出一个序列,求出这个序列的最长上升子序列。

序列A的上升子序列B定义如下:

B为A的子序列
B为严格递增序列
Input
第一行包含一个整数n,表示给出序列的元素个数。

第二行包含n个整数,代表这个序列。
1 <= N <= 1000
Output
输出给出序列的最长子序列的长度。

Sample Input
7
1 7 3 5 9 4 8
Sample Output
4


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
#define N 1001
int a[N];
int l[N];
int main()
{
    int i, n, j, max = 0;
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i];
    memset(l, 0, sizeof(l));

    l[0] = 1;
    for (i = 1; i < n; i++)
    {
        l[i] = 1;
        for (j = 0; j < i; j++)
            if (a[j] < a[i] && l[j] >= l[i])
                l[i] = l[j] + 1;
    }
    //这里注意下,在求的时候l[i]的意思是:以a[i]结尾的最长上升子序列。
    //但是,整个串的最长公共子序列可能不是以a[i]结尾。所以要遍历结尾,取最大值
    for (i = 0; i < n; i++)
        if (l[i] > max)
            max = l[i];
    cout << max << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/tttfu/p/11344915.html

时间: 2024-10-11 21:13:00

LIS模板题(Longest Ordered Subsequence)的相关文章

poj 2533 &amp; poj 1631 Longest Ordered Subsequence( LIS果题 )

题目链接: POJ 2533:http://poj.org/problem?id=2533 POJ 1631:http://poj.org/problem?id=1631 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1,

POJ 2533 Longest Ordered Subsequence(LIS模版题)

Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Accepted: 21120 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ...

poj 2533 Longest Ordered Subsequence(LIS)

Description A numeric sequence of ai is ordered ifa1 <a2 < ... < aN. Let the subsequence of the given numeric sequence (a1,a2, ..., aN) be any sequence (ai1,ai2, ..., aiK), where 1 <=i1 < i2 < ... < iK <=N. For example, sequence (1

POJ 2533 Longest Ordered Subsequence(裸LIS)

传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 61731   Accepted: 27632 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the

题解报告:poj 2533 Longest Ordered Subsequence(LIS)

Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, seq

POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]

题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ...,

[kuangbin带你飞]专题十二 基础DP1 N - Longest Ordered Subsequence POJ - 2533(最长上升子序列LIS)

N - Longest Ordered Subsequence POJ - 2533 题目链接:https://vjudge.net/contest/68966#problem/N 题目: 最长有序子序列如果a1 <a2 <... <aN,则排序ai的数字序列. 让给定数字序列(a1,a2,...,aN)的子序列为任何序列(ai1,ai2,...,aiK),其中1 <= i1 <i2 <... <iK <= N 例如,序列(1,7,3,5,9,4,8)具有有

POJ 2533 Longest Ordered Subsequence (LIS)

Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 35930   Accepted: 15779 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ...

POJ 2533 Longest Ordered Subsequence(dp LIS)

Language: Default Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 33986   Accepted: 14892 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric seq