Longest Ordered Subsequence

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 42914 Accepted: 18914

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

一个裸的 LIS

直接给状态转移方程: if (a[j]>a[i]) f[j]=max(f[j],f[i]+1);

#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[1005],f[1005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
if(a[j]>a[i]) f[j]=max(f[i]+1,f[j]);
for(int i=1;i<=n;i++)
f[0]=max(f[0],f[i]);
printf("%d",f[0]+1);//因为是从0开始的 所以要+1
}

POJ 2533 动态规划入门 (LIS)的更多相关文章

  1. nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)

    17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...

  2. POJ 2533 裸的LIS

    A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given ...

  3. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  4. poj 2533 Longest Ordered Subsequence 最长递增子序列

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...

  5. POJ 2533 最小上升子序列

    D - POJ 2533 经典DP-最长上升子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let th ...

  6. 洛谷P1028 数的计算 题解 动态规划入门题

    题目链接:https://www.luogu.com.cn/problem/P1028 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数 \(n\) ): 先输入一个自然数 \(n(n \ ...

  7. POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]

    题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...

  8. POJ 2533 Longest Ordered Subsequence(裸LIS)

    传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  9. LIS(n^2) POJ 2533 Longest Ordered Subsequence

    题目传送门 题意:LIS(Longest Increasing Subsequence)裸题 分析:状态转移方程:dp[i] = max (dp[j]) + 1   (a[j] < a[i],1 ...

随机推荐

  1. 删除DSO Change Log表数据

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. Ubuntu 16.04 + Caffe

    主要参考: https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide http://caffe.berke ...

  3. js判断鼠标进入以及离开容器的方向

      (注:以下代码涉及到jQuery,建议前端大牛绕路~~~) 1.遇到的问题      如图当鼠标右箭头位置上下移动的时候  下面的城市列表容器不能隐藏. 2.方法: 网上搜了些前端大牛们的解决办法 ...

  4. 推荐10个bootstrap及其他框架的后台管理模板

    相对于网站前台炫目多彩的设计,网址后台的设计模板貌似有点少,在这里推荐10个可以免费下载的~ 1.自适应超酷整站 win8风格的Bootstrap响应式网站后台管理模板-Apricot 2.boots ...

  5. suds调用webservice

    一.安装 pip install suds 二.日志 import logging logging.basicConfig(level=logging.INFO) logging.getLogger( ...

  6. M1卡介绍

    本文整理自网络. M1卡是指菲利浦下属子公司恩智浦出品的芯片缩写,全称为NXP Mifare1系列,常用的有S50及S70两种型号,目前都有国产芯片与其兼容,属于非接触式IC卡.最为重要的优点是可读可 ...

  7. c++虚函数的作用是什么?

    <深入浅出MFC>中形容虚函数是执行一般化操作,一直没有领悟要点.现在的体悟是抽象,先前考虑问题都是由抽象到具象,比如下文中的示例,由上(虚基类的「怪物」)至下(派生类的三个子类「狼」「蜘 ...

  8. 你真的会写单例模式吗-------Java实现

    转载: 你真的会写单例模式吗--Java实现 单例模式可能是代码最少的模式了,但是少不一定意味着简单,想要用好.用对单例模式,还真得费一番脑筋.本文对Java中常见的单例模式写法做了一个总结,如有错漏 ...

  9. @keyframes

    通过 @keyframes 规则,您能够创建动画. @keyframes movelike{ from{right:1205px;} to{right:0px}} 创建动画的原理是,将一套 CSS 样 ...

  10. jQuery实现加入购物车飞入动画效果

    <script src="jquery.js"></script> <script src="jquery.fly.min.js" ...