POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)
题目链接:http://poj.org/problem?id=2533
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 55459 | Accepted: 24864 |
Description
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
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e6+; int dp[MAXN], a[MAXN]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ; i<=n; i++)
scanf("%d",&a[i]); ms(dp, );
for(int i = ; i<=n; i++)
for(int j = ; j<i; j++)
if(j== || a[i]>a[j])
dp[i] = max(dp[i], dp[j]+); int ans = -INF;
for(int i = ; i<=n; i++)
ans = max(ans, dp[i]);
printf("%d\n",ans);
}
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e6+; int dp[MAXN], a[MAXN]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ; i<=n; i++)
scanf("%d",&a[i]); int len = ;
for(int i = ; i<=n; i++)
{
if(i== || a[i]>dp[len])
dp[++len] = a[i]; else
{
int pos = lower_bound(dp+,dp++len,a[i]) - (dp+);
dp[pos+] = a[i];
}
}
printf("%d\n",len);
}
}
POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)的更多相关文章
- POJ2533 Longest Ordered Subsequence 【最长递增子序列】
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32192 Acc ...
- 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
- 【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)
Longest Ordered Subsequence 搬中文 Descriptions: 给出一个序列,求出这个序列的最长上升子序列. 序列A的上升子序列B定义如下: B为A的子序列 B为严格递增序 ...
- [POJ2533]Longest Ordered Subsequence<dp>
题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...
- POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)
传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...
- POJ - 2533 Longest Ordered Subsequence(最长上升子序列)
d.最长上升子序列 s.注意是严格递增 c.O(nlogn) #include<iostream> #include<stdio.h> using namespace std; ...
- POJ2533——Longest Ordered Subsequence(简单的DP)
Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- (线性DP LIS)POJ2533 Longest Ordered Subsequence
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 66763 Acc ...
- poj-2533 longest ordered subsequence(动态规划)
Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...
随机推荐
- Google JavaScript代码风格指南
Google JavaScript代码风格指南 修正版本 2.28 Aaron Whyte Bob Jervis Dan Pupius Eric Arvidsson Fritz Schneider R ...
- 如何设置目标并发(或者目标RPS)?
基本概念 首先您需要了解什么是并发用户.TPS 和它们之间的关系. 并发用户:指的是现实系统中同时操作业务的用户,在性能测试工具中一般称为虚拟用户(Virutal User).一般是站在客户侧评估的角 ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...
- hust 1017 dancing links 精确覆盖模板题
最基础的dancing links的精确覆盖题目 #include <iostream> #include <cstring> #include <cstdio> ...
- 尽量写出大家都能看懂的ReactJS入门教程
个人感觉ReactJS相比于传统的JS框架还是挺有意思的,主要是它将JS代码和HTML代码完美的结合在了一起,有点jsp把java代码和html混在一起写的意思?但是它通过组件的形式实现了代码可复用, ...
- 【HDOJ6343】Graph Theory Homework(贪心)
题意: 给定n个点,每个点有权值a[i],从A走到B的花费是下取整sqrt(a[i]-a[j]),求从1号点走到n号点的最小花费 1<=n,a[i]<=1e5 思路: #include&l ...
- ArrayList内部实现原理
数组在创建的时候长度是固定的,那么就有往ArrayList中不断添加对象的时候,那么ArrayList是如何管理这些数组的? ArrayList内部通过Object[]实现,我们通过分析ArrayLi ...
- Spring中使用byType实现Beans自动装配
以下内容引用自http://wiki.jikexueyuan.com/project/spring/beans-auto-wiring/spring-autowiring-byType.html: 此 ...
- 【转】AOP
原文:http://blog.csdn.net/zhoudaxia/article/details/38502347 .---------------------------------------- ...
- VC++ 2010编译错误 fatal error C1189 error This file requires _WIN32_WINNT to be #defined at least
打开你的C++工程,找到里面的stdafx.h文件,然后把下面的红色内容替换成绿色的 参考:http://blog.csdn.net/dongliqiang2006/article/details/5 ...