Longest Ordered Subsequence

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

Source

Northeastern Europe 2002, Far-Eastern Subregion

题解 最长上升子序列,动态规划。

#include<stdio.h>
#include<string.h>
int a[100001];
int dp[100001];
int max(int a,int b)
{
return a>b?a:b;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]); memset(dp,0,sizeof(dp));
int res=0;
for(int i=0;i<n;i++)
{
dp[i]=1;
for(int j=0;j<=i;j++)
{
if(a[i]>a[j])
{
dp[i]=max(dp[i],dp[j]+1);
// dp[i]=dp[j]+1;
} res=max(res,dp[i]);
}
} printf("%d\n",res);
} return 0;
}

最新文章

  1. ACM/ICPC 之 DP解有规律的最短路问题(POJ3377)
  2. ADO 连接数据库,取到VT_DATE型日期转换成 int型
  3. iOS集成丁香园DXY OAuth 登陆 swift代码示例
  4. PHP ElasticSearch的使用
  5. noi 1944 吃糖果
  6. js-条件语句、循环语句
  7. 转 Android学习 之 ColorStateList按钮文字变色
  8. JavaWeb高性能开发(一)
  9. 20150414---ListView简介(web)
  10. solr源码导入eclipse
  11. appium安装 For windows
  12. STM32高级定时器TIM1产生两路互补的PWM波(带死区)
  13. shell快捷键
  14. github管理的建立(SSH Key生成步骤)
  15. mssql sqlserver 自动备份存储过程的方法分享
  16. 编译openwrt时报错:g++: internal compiler error: Killed (program cc1plus)
  17. 命名自我规约manual
  18. 【转】Vim速查表-帮你提高N倍效率
  19. 一些值得收藏的MySQL知识链接
  20. 深入理解 Java 虚拟机

热门文章

  1. &lt;llinux下kvm虚拟化&gt;
  2. &lt;Linux系统isosize指令用法&gt;
  3. jdbc操作数据库的步骤
  4. OpenStack Ocata Telemetry 数据收集服务
  5. MySQL JOIN | 联结
  6. 符号替换问题:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
  7. 子元素的margin-top会影响父元素
  8. Struts2笔记2
  9. Hibernate笔记7--JPA CRUD
  10. 【Java/Android性能优 4】PreloadDataCache支持预取的数据缓存,使用简单,支持多种缓存算法,支持不同网络类型,扩展性强