51Nod-1134 最长递增子序列

来源:互联网 发布:lrc制作软件 编辑:程序博客网 时间:2024/05/22 17:47

1134 最长递增子序列
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注
给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)
例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。
Input
第1行:1个数N,N为序列的长度(2 <= N <= 50000)
第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)
Output
输出最长递增子序列的长度。
Input示例
8
5
1
6
8
2
4
5
10
Output示例
5

通常都使用动态规划解决此类问题,但使用dilworth定理更简单。

#include<iostream>using namespace std;int arr[50006];int index=0;int main(){    int n,j,num;    cin>>n;    for (int i=0;i<n;i++)    {        cin>>num;        for (j=0;j<index;j++)        {            if (num<=arr[j])            {                arr[j]=num;                break;            }        }        if(j==index)            arr[index++]=num;    }    cout<<index;    return  0;}
原创粉丝点击