• [POJ2533]Longest Ordered Subsequence<dp>


    题目链接:http://poj.org/problem?id=2533

    描述:

    A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1a2, ..., aN) be any sequence (ai1ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
    Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

    翻译:

    找一串数字最长上升子序列的数字个数。(手动狗头)

    没有难度的一个dp题,范围不算大,最普通的方法就可以过了

    想优化看到了其他博主说的二分,不过我没有用

    等复习到二分再来试试吧

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    int n,a[10005],dp[10005],ans;
    
    int main(){
        n=read();
        for(int i=1;i<=n;i++)
            a[i]=read();
        for(int i=2;i<=n;i++)
            for(int j=1;j<i;j++)
                if(a[i]>a[j])dp[i]=max(dp[i],dp[j]+1);
        for(int i=1;i<=n;i++)
            ans=max(ans,dp[i]);
        cout<<ans+1;
        return 0;
    }
    View Code
  • 相关阅读:
    iOS SpriteKit 字体设置无效问题
    2021又来到了!
    其他人员优点
    自己缺点记录
    领导优点分析-于总
    领导优点分析-黄总
    Linux CentOS 7 安装字体库 & 中文字体
    mysql备份数据库
    MySQL mysqldump 导入/导出 结构&数据&存储过程&函数&事件&触发器
    mysql 导入导出数据库以及函数、存储过程的介绍
  • 原文地址:https://www.cnblogs.com/Danzel-Aria233/p/12292430.html
Copyright © 2020-2023  润新知