POJ 2533
最长上升子序列裸题
在网上看到有两种方法...一种复杂度O(N^2),一种O(NlogN)。orz
O(N^2):
#include<cstdio>
#define N 1001
int main()
{
int n,ans;
int a[N],d[N]; while(~scanf("%d",&n)){
for(int i=; i<=n; i++)
scanf("%d",&a[i]); ans=;
for(int i=; i<=n; i++)
{
d[i]=;
for(int j=; j<=i-; j++)
{
if(a[i]>a[j] && d[i]<d[j]+)
d[i]=d[j]+;
}
if(d[i]>ans)
ans=d[i];
}
printf("%d\n",ans);
}
return ;
}
O(NlogN):
#include <cstdio>
using namespace std; const int maxn = + ;
int n, num[maxn], LIS[maxn]; int binary_search(int start, int end, int target)
{
while (end > start) {
int mid = (end + start) / ;
if (target > LIS[mid])
start = mid + ;
else
end = mid;
}
return start;
} int lis()
{
LIS[] = num[];
int maxl = ;
for (int i = ; i <= n; ++i) {
if (num[i] > LIS[maxl])
LIS[++maxl] = num[i];
else {
int pos = binary_search(, maxl, num[i]);
LIS[pos] = num[i];
}
}
return maxl;
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; ++i)
scanf("%d", &num[i]);
printf("%d\n", lis());
}
POJ 2533的更多相关文章
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)
17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...
- POJ 2533 最小上升子序列
D - POJ 2533 经典DP-最长上升子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let th ...
- poj 2533 Longest Ordered Subsequence(dp)
题目:http://poj.org/problem?id=2533 题意:最长上升子序列.... 以前做过,课本上的思想 #include<iostream> #include<cs ...
- OpenJudge 2757 最长上升子序列 / Poj 2533 Longest Ordered Subsequence
1.链接地址: http://poj.org/problem?id=2533 http://bailian.openjudge.cn/practice/2757 2.题目: 总Time Limit: ...
- poj 2533 Longest Ordered Subsequence(线性dp)
题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定 ...
- 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)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- POJ 2533——Longest Ordered Subsequence(DP)
链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...
随机推荐
- cocos2d-html5 笔记5: 事件
在cocos2d里面,通过Node的方式,将整个场景以及里面的object给组织起来,这样很容易画了,从root node开始遍历,把整棵树画出来就是了. 剩下就是animation,timer, 还 ...
- CPU 100%
http://www.cnblogs.com/xuehong1985/articles/757060.html
- cocos2d-x在android下的编译
$(call import-add-path,E:/cocos2d-2.0-x-2.0.3) include $(BUILD_SHARED_LIBRARY) http://www.cnblogs.co ...
- 关于Android LayoutInflater的解释
LayoutInflater的作用就是动态加载xml布局好的界面,类似于findViewById()来获取已经定义好的控件一样.不同点是LayoutInflater是用来找res/layout/下的x ...
- rsync同步工具学习笔记
rsync同步工具 1.rsync介绍 rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.rsync软件适用于unix/linux/windows等多种操作 ...
- python 操作word文档
因为工作需要操作一些word文档,记录一下学习思路 #-*- encoding: utf8 -*- import win32com from win32com.client import Dispat ...
- iOS开发 - 一个天真的搜索控制器的独白
文/Azen(简书作者)原文链接:http://www.jianshu.com/p/6d5327111511著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文 一.关于横向模块开发 ...
- 用HashSet的add方法谈hashcode和equals方法重写
本文主要通过用HashSet的add方法讲一下hashCode和equals方法重写.错误的地方望指正. 1.了解HashSet的add方法 了解一个方法的好办法是看源码,所以先看源码 private ...
- H - Frequent values
Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasi ...
- Clairewd’s message
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...