动态规划——E (LIS())最长上升子序列
Description
Input
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
For each set of data the program prints the result to the standard output from the beginning of a line.
Sample Input
6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1
Sample Output
3
1
1
Hint
#include <cstdio>
using namespace std;
const int L=;
int a[L],b[L];
int n;
void init()
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
}
int bin(int r,int k)
{
int l=;
while(l<=r)
{
int mid=(l+r)/;
if(k>b[mid])
l=mid+;
else
r=mid-;
}
return l;
}
int work()
{
int i,j,k;
int c=;
for(i=;i<n;i++)
if(c==||a[i]>b[c])
b[++c]=a[i];
else
{
k=bin(c,a[i]);
b[k]=a[i];
}
return c;
}
int main()
{
while(scanf("%d",&n)==)
{
init();
printf("%d\n",work());
}
return ;
}
动态规划——E (LIS())最长上升子序列的更多相关文章
- 动态规划模板1|LIS最长上升子序列
LIS最长上升子序列 dp[i]保存的是当前到下标为止的最长上升子序列的长度. 模板代码: int dp[MAX_N], a[MAX_N], n; int ans = 0; // 保存最大值 for ...
- 算法设计 - LCS 最长公共子序列&&最长公共子串 &&LIS 最长递增子序列
出处 http://segmentfault.com/blog/exploring/ 本章讲解:1. LCS(最长公共子序列)O(n^2)的时间复杂度,O(n^2)的空间复杂度:2. 与之类似但不同的 ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- hdu 5256 序列变换(LIS最长上升子序列)
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需要修改多 ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
- 300. Longest Increasing Subsequence(LIS最长递增子序列 动态规划)
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 动态规划(DP),最长递增子序列(LIS)
题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...
- 低价购买 (动态规划,变种最长下降子序列(LIS))
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
随机推荐
- 自己写的自动生成动态边框的jquery小插件
思路就是在元素四周添加<ul>列表,然后周期性地改变它的颜色,实现动态的效果,不支持ie7.ie8 预览链接http://gorey.sinaapp.com/myBorder/border ...
- eclipse build很慢的时候,有可能是js文件编译验证慢的问题
第一步: 去除eclipse的JS验证: 将windows->preference->Java Script->Validator->Errors/Warnings-> ...
- 【转】 iOS开发UI篇—UIScrollView控件实现图片轮播
原文:http://www.cnblogs.com/wendingding/p/3763527.html iOS开发UI篇—UIScrollView控件实现图片轮播 一.实现效果 实现图片的自动轮播 ...
- sql server主动推送客户端更新数据
小谈需求: 最近工作上接到一个需求,做一个web展示数据的报表,最好能实时更新,不限制所用技术. 第一个问题:web服务器推送给浏览器新数据,一开始我想到的最快的最简单的方法就是 在web页面上js轮 ...
- node 裁剪图片
1.前端一般用Jcrop这个jq插件 要返回 x: 图片 x坐标 y: 图片 y坐标 w: 图片 宽度 h: 图片 高度 2.node 实现 var images = require("im ...
- confluence5.8.10的使用
之前在windows上安装了confluence5.8.10,结果有一天知什么缘故,数据库数据损坏,知识库彻底打不开了,所有的文档都付之东流,真的不是一般心痛.因此考虑将其装到linux机器上,因为t ...
- linux 获取cpu百分比
vmstat 1 |head -n 4 |tail -n 1 |awk '{print $13}'
- html良好结构-之豆瓣风格
良好HTML结构 1 结构层次 unit> hd+ unit-wrap>section>item2 语议化的结构 html5 html 语议 ck-box-unit ck-hd-wr ...
- github的package.json内容
补充:npm的init命令生成package.json Name 必须字段. 小提示: 不要在name中包含js, node字样: 这个名字最终会是URL的一部分,命令行的参数,目录名,所以不能以点号 ...
- magento后台 Fatal error: Call to a member function getId() on a non-object in错误
后台分类管理出现错误 Fatal error: Call to a member function getId() on a non-object in 在数据库中运行以下sql语句 INSERT I ...