Longest Ordered Subsequence POJ - 2533 dp 最长上升/不下降 子序列

#include<iostream>
using namespace std ;
const int N=1010;
int f[N];
int a[N];
int n;
int main() {
    cin>>n;
    for(int i=1; i<=n; i++) cin>>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]);
    cout<<res<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12238576.html

时间: 2024-11-08 16:55:48

Longest Ordered Subsequence POJ - 2533 dp 最长上升/不下降 子序列的相关文章

N - Longest Ordered Subsequence POJ 2533 (最长上升子序列 )

N - Longest Ordered Subsequence Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numer

[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)具有有

Longest Ordered Subsequence POJ - 2533 最长上升子序列dp

题意:最长上升子序列nlogn写法 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int dp[1005]; 7 int a[1005]; 8 int main(){ 9 int n; 10 while(cin>>n){ 11 for(int i=0;i<n;i++){ 12

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

POJ2533——Longest Ordered Subsequence(简单的DP)

Longest Ordered Subsequence DescriptionA 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

poj 2533 Longest Ordered Subsequence(线性dp)

题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定义状态dp[i]为以在所有的递增子序列中以A[i]为递增子序列的最后一个数字的所有递增子序列中的最大长度: 如:根据题目,在所有的以3结尾的递增子序列有[3]和[1, 3],所以dp[2] =2; 2)状态转移方程:因为当A[j] < A[i]时(0<= j < i),dp[i] = Max

POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)

Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 38980   Accepted: 17119 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思想】

Longest Ordered Subsequence Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 6   Accepted Submission(s) : 1 Problem Description A numeric sequence of ai is ordered ifa1 < a2 < ... < aN. Let t

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 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)