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 ...
随机推荐
- HDU 5469 Antonidas
Antonidas Time Limit: 4000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 【HTML/XML 6】XML文档的基本组成
导读:大致上,一个XML文档可以由三个部分组成,即声明区.定义区和文档主体区.在XML文档中,各个组成部分都包含特定的内容,有着不同的作用.本篇博客,通过分析上篇博客中的XML实例,来了解XML文档 ...
- 【数学】codeforces A. Success Rate
http://codeforces.com/contest/773/problem/A [思路] 用 (x+a)/(y+b) = p/q 来表示其核心思想,其中a 为做对的题目,b为做的题目,则有x+ ...
- 可以学习相关框架【转:https://testerhome.com/topics/6283】
https://testerhome.com/topics/6283 单元测试方面(Java): Junit:本来想用我熟悉的testng,但是开发的同学说测试springmvc只能用Junit.所以 ...
- POJ 3248 Catch That Cow
http://poj.org/problem?id=3278 二维BFS #include <iostream> #include <stdio.h> #include < ...
- POJ 1017 Packet
http://poj.org/problem?id=1017 有1*1 2*2...6*6的物品 要装在 6*6的parcel中 问最少用多少个parcel 一直没有找到贪心的策略 问题应该出现在 总 ...
- BZOJ1775: [Usaco2009 Dec]Vidgame 电视游戏问题
n<=50个游戏机有花费,每个游戏机有Gi<=10种游戏,每种游戏有花费有收益,买了游戏机才能玩对应游戏,求最大收益. 这就是一个背包!不过有依存关系,就不会了! 方法一:f[i][j]表 ...
- C#的特性学习草稿
原文发布时间为:2008-11-22 -- 来源于本人的百度文章 [由搬家工具导入] 举个简单的例子: 先定义个特性 从Attribute继承,并标明用法 [AttributeUsage(Attrib ...
- [vijos1891]学姐的逛街计划
学姐的逛街计划 描述 doc 最近太忙了, 每天都有课. 这不怕, d ...
- oracle dtrace for linux
https://docs.oracle.com/cd/E37670_01/E37355/html/ol_config_dtrace.html#