码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2022.11.22Longest Ordered Subsequence POJ - 2533


    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, 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.

    Input

    The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

    Output

    Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

    Sample

    InputcopyOutputcopy
    7
    1 7 3 5 9 4 8
    4
    

     原题链接:传送门

    题意求最长上升子序列

    刚开始题意没看清写成a[j] <= a[i]了wa了好几发,上升子序列就不需要等于

    1. #include
    2. using namespace std;
    3. const int N = 1001;
    4. int a[N], dp[N];
    5. int main(){
    6. int n;
    7. cin >> n;
    8. int ans = 1;
    9. for(int i = 1; i <= n; i++) cin>>a[i];
    10. for(int i = 1; i <= n; i++){
    11. dp[i] = 1;
    12. for(int j = 1; j < i; j++){
    13. if(a[j] < a[i] && dp[j] + 1 > dp[i]){
    14. dp[i] = dp[j] + 1;
    15. }
    16. }
    17. if(dp[i] > ans) ans = dp[i];
    18. }
    19. cout << ans << endl;
    20. return 0;
    21. }

     

  • 相关阅读:
    DIN EN ISO 4589-2塑料 用氧指数法测定燃烧行为 第2 部分:室温试验
    【Vue】ElementUI实现登录注册
    C++模板元模板(异类词典与policy模板)- - - 中篇后续
    C++多态-联编
    牛客刷题——剑指offer(第7期)
    设计模式案例
    使用MapStruct简化entity、dto、dxo之间的属性复制
    pytest+yaml实现接口自动化框架
    【生物医学的前沿问题】在MRI扫描中自动识别胃肠病变组织的数学模型
    yo!这里是c++中的多态
  • 原文地址:https://blog.csdn.net/weixin_62802134/article/details/128010113
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号