POJ2533 Longest Ordered Subsequence 【最长递增子序列】
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 32192 | Accepted: 14093 |
Description
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
Output
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4
NYOJ原题
#include <stdio.h>
int arr[1002], dp[1002];
int main()
{
int n, i, j, ans;
scanf("%d", &n);
for(i = 1; i <= n; ++i) scanf("%d", arr + i);
dp[1] = ans = 1;
for(i = 2; i <= n; ++i){
for(dp[i] = 1, j = i - 1; j >= 1; --j){
if(arr[i] > arr[j] && dp[i] <= dp[j]){
dp[i] = dp[j] + 1;
if(dp[i] > ans) ans = dp[i];
}
}
}
printf("%d\n", ans);
return 0;
}
{
int n, i, j, ans;
scanf("%d", &n);
for(i = 1; i <= n; ++i) scanf("%d", arr + i);
dp[1] = ans = 1;
for(i = 2; i <= n; ++i){
for(dp[i] = 1, j = i - 1; j >= 1; --j){
if(arr[i] > arr[j] && dp[i] <= dp[j]){
dp[i] = dp[j] + 1;
if(dp[i] > ans) ans = dp[i];
}
}
}
printf("%d\n", ans);
return 0;
}
POJ2533 Longest Ordered Subsequence 【最长递增子序列】的更多相关文章
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列(LIS)
两种算法 1. O(n^2) #include<iostream> #include<cstdio> #include<cstring> using namesp ...
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- zoj 2136 Longest Ordered Subsequence 最长上升子序列 新思路
Longest Ordered Subsequence Time Limit: 2 Seconds Memory Limit: 65536 KB A numeric sequence of ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...
- 673. Number of Longest Increasing Subsequence最长递增子序列的数量
[抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...
随机推荐
- [Erlang危机](4.5)第四章练习
原创文章.转载请注明出处:server非业余研究http://blog.csdn.net/erlib 作者Sunface 联系邮箱:cto@188.com Exercises 练习 Review Qu ...
- synchronized和进程间通信(转)
关于JAVA多线程同步 JAVA多线程同步主要依赖于若干方法和关键字 1 wait方法: 该方法属于Object的方法,wait方法的作用是使得当前调用wait方法所在部分(代码块)的线程停止执行, ...
- SOA两个接口通常用于实现更:SOAP vs REST
SOA协作架构异构系统,因此,一个跨操作系统的需求.跨语言的通用信息交换格公式. SOAP和REST它们是基于消息正文文本,在跨平台方面相比二进制消息优点.因此,作为选择SOA实施通常用于界面.但SO ...
- k8s google sample - guestbook
Redis读写分离作为存储 PHP网页作为前端 github地址 https://github.com/kubernetes/kubernetes/blob/release-1.1/examples/ ...
- Cocos2d-x3.3它DrawPrimitivesTest分析
1.代码列表 2.VisibleRect类 该类是test-cpp自带工具类 3.HelloWorldScene类 同前面代码 4.DrawPrimitivesDemo类 1).h文件 #includ ...
- IIS7安装场景对照表
原文 IIS7安装场景对照表 Default Server Install Components Server Manager Update Name Static Content IIS-Stati ...
- ssh无密码登陆(转)
[0]写在前面 由于ssh 实现的是免密码登陆,大致步骤是: 0.1) client通过ssh登陆到server: 0.2) server检查家目录下的.ssh文件, 并发送公钥文件 authoriz ...
- 最近ubuntu 14.04 cpu高入住故障排除
最近linux始终使用cpu实现全值, 双核cpu这始终是一个核心100%,还有的正常核.top这一发现输入法框架fcitx加载,直接kill它,不能用于发现狗输入法,令: fcitx fcitx-q ...
- Android——保存并读取文件
Context.MODE_PRIVATE:为默认操作模式,代表该文件是私有数据,仅仅能被应用本身訪问,在该模式下,写入的内容会覆盖原文件的内容,假设想把新写入的内容追加到原文件里.能够使用Contex ...
- ASP.NET MVC5 插件机制中插件的简单实现
Autofac 依赖注入 ASP.NET MVC5 插件机制中插件的简单实现 一.前言 由于项目业务复杂,创建了多个插件并把他们放在了不同的项目中,项目使用AutoFac做的IOC:但是主项目可以注入 ...