首页 > 学院 > 开发设计 > 正文

poj2533纯最长上升子序列

2019-11-06 06:24:45
字体:
来源:转载
供稿:网友
/-------------------------------------------------------没什么好说的纯最长上身子序列#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn = 1000+10;int dp[maxn];int num[maxn];int n;int lis(){    int core = 1, ans = 1;    dp[1] = 1;    for(int i = 2; i <= n; i++){        int core = 0;        for(int j = 1; j < i; j++){            if(num[j] < num[i] && dp[j] > core){                core = dp[j];            }        }        dp[i] = core + 1;        if(dp[i] > ans) ans = dp[i];    }    return ans;}int main (){    while(scanf("%d", &n) != EOF){        for(int i = 1; i <= n; i++)scanf("%d", &num[i]);        cout << lis() << endl;    }    return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表