【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)
Longest Ordered Subsequence
搬中文
Descriptions:
给出一个序列,求出这个序列的最长上升子序列。
序列A的上升子序列B定义如下:
- B为A的子序列
- B为严格递增序列
Input
第一行包含一个整数n,表示给出序列的元素个数。
Output
输出给出序列的最长子序列的长度。
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4
题目链接:
https://vjudge.net/problem/POJ-2533
就是最长子序列,没啥说的,简单dp
二分查找的函数有 3 个:
lower_bound(起始地址,结束地址,要查找的数值) 地址:前闭后开。返回的是第一个大于或等于数值出现的位置,如果数值大于数组中全部元素,返回的是结束地址。
upper_bound(起始地址,结束地址,要查找的数值) 地址:前闭后开。返回的是第一个大于数值出现的位置,如果数值大于数组中全部元素,返回的是结束地址。
binary_search(起始地址,结束地址,要查找的数值) 返回的是是否存在这么一个数,是一个bool值。
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define Maxn 1000+10
using namespace std;
int dp[Maxn];
int a[Maxn];
int main()
{
int n;
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i];
int len=;//最长子序列长度
dp[]=a[];
for(int i=;i<=n;i++)
{
if(a[i]>dp[len])//大于前一个,则赋值
dp[++len]=a[i];
else
{
//小于,则找到第一个大于a[i]的值,并把它替代了
int t=lower_bound(dp+,dp+len,a[i])-dp;
dp[t]=a[i];
}
}
cout<<len<<endl;
return ;
}
【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)的更多相关文章
- 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 ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- 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与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- 题解报告: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(最长上升子序列(NlogN)
传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 Acc ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
随机推荐
- 为什么RChain区块链上一定要有REV?
RChain区块链网络上一定要有REV吗?它的作用是什么?在这篇文章里,RChain创始人Mr. Greg Meredith做了详细解读,便于业界和社区对RChain网络有更深入的认识. 作者:Gre ...
- Static、Final、static final
Static.Final.static final final可以修饰:属性,方法,类,局部变量(方法中的变量) 用final关键字修饰的变量,只能进行一次赋值操作,并且在生存期内不可以改变它的值. ...
- mac电脑下使用fcrackzip破解zip压缩文件密码
fcrackzip简介 fcrackzip是一款专门破解zip类型压缩文件密码的工具,工具小巧方便.破解速度快,能使用字典和指定字符集破解,适用于linux.mac osx 系统 fcrackzip安 ...
- Git详解之内部原理
前言 不管你是从前面的章节直接跳到了本章,还是读完了其余各章一直到这,你都将在本章见识 Git 的内部工作原理和实现方式.我个人发现学习这些内容对于理解 Git 的用处和强大是非常重要的,不过也有人认 ...
- systemctl中添加mysql服务
由于mysql的版本更新,许多术语有了新含义,所以需要特别指出,mysqld.service 等价于mysqld vim /usr/lib/systemd/system/mysqld.service ...
- Codeforces Round #618 (Div. 2)
题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...
- session、cookie、sessionStorage、localStorage的简要理解
一.cookie和session 首先 session 和 cookie 用于浏览器客户端与服务端数据交互,通过会话的方式跟踪浏览器用户身份. 1.cookie (1).一般由服务器生成,可以设置失效 ...
- Ubuntu解决 MariaDB无密码就可以登录的问题
使用apt-get来安装mysql,安装好之后发现安装的是 MariaDB,如下,无需密码既可以登录了.即使使用mysqladmin或mysql_secure_installation 设置好密码,用 ...
- kubernetes容器端口设置的坑
1.使用dockerhub上面的镜像的时候,先到dockerhub上看镜像的相关信息. 2.不能随便修改容器应用的镜像,会出问题.
- LeetCode 200. Number of Islands 岛屿数量(C++/Java)
题目: Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is s ...