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 ...
随机推荐
- python使用smtplib库和smtp.qq.com邮件服务器发送邮件(转)
使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPAuthenticationError 主要的原因就是口令和帐号信息不对,这里我们 ...
- 跑ssis分组差错:没有关联“”。假设无法找到一个特定的连接元件,Connections 这种错误发生的收集
跑ssis分组差错:没有关联"".假设无法找到一个特定的连接元件,Connections 这种错误发生的收集. 在网上搜了一下,解决方法: 打开SqlServer Configur ...
- 编程算法 - 圆圈中最后剩下的数字(循环链表) 代码(C++)
圆圈中最后剩下的数字(循环链表) 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 0,1...,n-1这n个数字排成一个圆圈, 从数字0開始 ...
- Eclipse-----jrebel实现jetty热部署
步骤1:下载jrebel将文件解压缩到任意文件夹 步骤2:配置jetty watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/f ...
- 解决TD于ie10没有问题,
.打开命令提示符下,输入 gpedit 回车打开组策略编辑器: .计算机配置-管理模版-全部设置-关闭数据运行保护,双击打开.选择已启用.关闭组策略浏览器. .命令提示符下输入gpupdate/for ...
- [Tool]利用Advanced Installer建立x86/x64在一起的安装程式
原文 [Tool]利用Advanced Installer建立x86/x64在一起的安装程式 之前使用InstallShield做安装程式时,如果要将程式放在Program Files的话,需要分别针 ...
- Linux Howto
1. Customize the Xfce menu http://wiki.xfce.org/howto/customize-menu
- hdu 1150 Machine Schedule (经典二分匹配)
//A组n人 B组m人 //最多有多少人匹配 每人仅仅有匹配一次 # include<stdio.h> # include<string.h> # include<alg ...
- Oracle按不同时间分组统计
Oracle按不同时间分组统计 Oracle按不同时间分组统计的sql 如下表table1: 日期(exportDate) 数量(amount) -------------- ----------- ...
- Linux学习笔记——举例说,makefile 添加宏定义
0.前言 从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile.假设自己动手写一个makefile总认为非常吃力. 所以特意 ...