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 Input
7
1 7 3 5 9 4 8
Sample Output
4

题目大意是让你求给的数字序列的最大上升子序列,直接上DP,每个位置的dp数组值就是当前位置之前的所有比自己小的上升子序列的长度,两重循环就可以解决。

AC代码

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int num[1005];
int dp[1005];
int main()
{int N;while(scanf("%d",&N)!=EOF){memset(dp,0,sizeof(dp));int mmax=-1;for(int i=1;i<=N;i++)cin>>num[i];for(int i=1;i<=N;i++){for(int j=1;j<i;j++)if(num[i]>num[j])dp[i]=max(dp[i],dp[j]+1);if(dp[i]==0) dp[i]=1; mmax=max(dp[i],mmax);}cout<<mmax<<endl;}return 0;
}

Longest Ordered Subsequence 最长上升子序列+DP相关推荐

  1. C++longest increasing subsequence 最长递增子序列的实现之二(附完整源码)

    C++longest increasing subsequence 最长递增子序列的实现 C++longest increasing subsequence 最长递增子序列的的实现完整源码(定义,实现 ...

  2. C++longest common subsequence最长公共子序列的实现(附完整源码)

    C++longest common subsequence最长公共子序列 longest common subsequence最长公共子序列的完整源码(定义,实现,main函数测试) longest ...

  3. C++longest increasing subsequence 最长递增子序列的实现之一(附完整源码)

    C++longest increasing subsequence 最长递增子序列的实现 C++longest increasing subsequence 最长递增子序列的的实现完整源码(定义,实现 ...

  4. Leetcode300. Longest Increasing Subsequence最长上升子序列

    给定一个无序的整数数组,找到其中最长上升子序列的长度. 示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4. 说 ...

  5. 300 Longest Increasing Subsequence 最长上升子序列

    给出一个无序的整形数组,找到最长上升子序列的长度. 例如, 给出 [10, 9, 2, 5, 3, 7, 101, 18], 最长的上升子序列是 [2, 3, 7, 101],因此它的长度是4.因为可 ...

  6. leetcode 1143. Longest Commom Subsequence 最长公共子序列(中等)

    一.题目大意 标签: 动态规划 https://leetcode.cn/problems/longest-common-subsequence 给定两个字符串 text1 和 text2,返回这两个字 ...

  7. 【POJ - 2533】Longest Ordered Subsequence(四种方法解决最长上升子序列 含二分优化版本)

    题干: Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 41944   Accepted: 18453 Description ...

  8. C++longest palindromic subsequence最长回文子序列算法实现(附完整源码)

    C++longest palindromic subsequence最长回文子序列算法 C++longest palindromic subsequence最长回文子序列算法实现完整源码(定义,实现, ...

  9. Vijos P1571 笨笨的导弹攻击【最长上升子序列+DP】

    背景 在那遥远的地方,有个小目标-- 笨笨:导弹准备! 路人甲:(这么小个目标都要欺负--)老大,导弹只有一部分可以用-- 笨笨:不管那么多,有多少就打多少! 描述 为了彻底打击目标,笨笨要使用足够多 ...

最新文章

  1. shell 脚本 进行sqlite3初始化
  2. Devstack配置负载均衡,负载均衡版本V2
  3. go get 指定版本_没有VPS搭建govanityurls服务?别急!你依然可以自定义Go包导入路径...
  4. memcache和memcached的区别
  5. 【小白学习PyTorch教程】五、在 PyTorch 中使用 Datasets 和 DataLoader 自定义数据
  6. 企业中的微服务:敌是友?
  7. 使用ABP打造SAAS系统(2)——前端框架选择
  8. 【USACO Feb 2014】Cow Decathlon
  9. 诛仙服务器列表文件,诛仙云服务器
  10. Float Protocol将于5月7日至10日进行FLOAT代币创世发布
  11. 为什么有些人电脑,电视,家电坏了首先是换新的,而不是维修?
  12. HarmonyOS 2.0:正式开源,年底面向开发者发布智能手机 Beta 版本
  13. Spring_02 注入类型值、利用引用注入类型值、spring表达式、与类相关的注解、与依赖注入相关的注解、注解扫描...
  14. DevExpress 小结
  15. 一、网络知识 1.计算机网络原理
  16. 北航计算机学院复试流程,2018北航计算机考研复试经验
  17. 智能交通——车辆属性识别
  18. 清明节,我想起了我的外公
  19. deepin 开启root权限
  20. 使用kmean进行图像分割 使用CRFs进行分割后处理

热门文章

  1. 1.6.jquerymobile--列表
  2. 12月江苏计算机考试报名入口,江苏2019年12月计算机等级报名时间丨报名系统
  3. 武汉职业技术学院技能高考计算机专业分数线,武汉职业技术学院历年分数线 2021武汉职业技术学院录取分数线...
  4. Sharepoint 自定义搜索
  5. Relatives POJ - 2407(不打表的欧拉函数 单求)
  6. QGraphicsView,QGraphicsScene,QGraphicsItem
  7. Leo-io 的C语言实现简单五子棋游戏观后感
  8. 结对项目--地铁出行路线规划程序(续)——附加题
  9. Java程序猿笔试面试之String1
  10. 【Java从0到架构师】Spring - 复杂对象、Converter