poj 3670(LIS)
// File Name: 3670.cpp
// Author: Missa_Chen
// Created Time: 2013年07月08日 星期一 21时15分34秒 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <vector>
#include <time.h> using namespace std; #define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = 3e4 + ;
int a[maxn], dp[maxn], D[maxn], len, n;
//dp[i]表示以第i个元素为子序列最后一个元素的LIS长度。
//D[len]表示上升子序列长度为len的最后一个元素。
int LIS()
{
len = ;
memset(dp, , sizeof(dp));
memset(D, , sizeof(D));
int ret = ;
for (int i = ; i <= n; ++i)
{
if (a[i] >= D[len])
{
dp[i] = len + ;
D[++len] = a[i];
}
else
{
int low = , high = len, tmp = ;
while (low <= high)
{
int mid = (low + high) >> ;
if (D[mid] <= a[i])
{
tmp = mid;
low = mid + ;
}
else
high = mid - ;
}
dp[i] = tmp + ;
D[tmp + ] = a[i];
}
ret = max(ret, dp[i]);
}
return ret;
}
int main()
{
while (~scanf("%d",&n))
{
for (int i = ; i <= n; ++i)
scanf("%d", &a[i]);
int ans = LIS();
reverse(a + , a + n + );
ans = max(ans, LIS());
printf("%d\n", n - ans);
}
return ;
}
poj 3670(LIS)的更多相关文章
- POJ 3670 , 3671 LIS
题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列. 当然3671是只能升序,所以更简单一点. 然后就没有什么了,用二分的方法求LIS即可. ...
- POJ 3670 Eating Together (DP,LIS)
题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #inclu ...
- POJ 3670 DP LIS?
权值为1~3 好了 此题是水题-- i表示到了第i个数,j表示结尾的数是j f[i][j]=min(f[i][j],f[i-1][k]+(a[i]!=j)) 1<=k<=j 最长上升的. ...
- POJ 3670 Eating Together(LIS)
Description The cows are so very silly about their dinner partners. They have organized themselves i ...
- poj 1836 LIS变形
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submiss ...
- poj 1631 LIS
题目链接:http://poj.org/problem?id=1631 #include <cstdio> #include <cstring> #include <io ...
- POJ 3670 Eating Together 二分解法O(nlgn)和O(n)算法
本题就是一题LIS(最长递增子序列)的问题.本题要求求最长递增子序列和最长递减子序列. dp的解法是O(n*n),这个应该大家都知道.只是本题应该超时了. 由于有O(nlgn)的解法. 可是因为本题的 ...
- E-Eating Together(POJ 3670)
Eating Together Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5579 Accepted: 2713 D ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
随机推荐
- JQuery日记_5.14 Sizzle选择器(七)
上篇说道,tokenize方法会把selector切割成一个个selector逻辑单元(如div>a是三个逻辑单元 'div','>','a')并为之片段赋予相应类型的过滤函数. for ...
- JAVA加解密 -- Base64加解密
Base64算法实现:可以将任意的字节数组数据,通过算法,生成只有(大小写英文.数字.+./)(一共64个字符)内容表示的字符串数据. private static final String str ...
- J2EE之EJB
EJB是sun的JavaEEserver端组件模型,最大的用处是部署分布式应用程序.EJB把使用java开发的server组件的部署和开发进行标准化. 凭借java跨平台的优势.用EJB技术部署的分 ...
- UICollectionViews有了简单的重排功能
代码地址如下:http://www.demodashi.com/demo/13213.html 一.前言 我是UICollectionView的忠实粉丝.这个类比起它的老哥UITableView类具有 ...
- iOS学习笔记-地图MapKit入门
代码地址如下:http://www.demodashi.com/demo/11682.html 这篇文章还是翻译自raywenderlich,用Objective-C改写了代码.没有逐字翻译,如有错漏 ...
- winform MDI子窗口闪动问题
在网上看到的 不知道什么原理但真的很实用 将下面的代码随便放到主窗体的任何一个地方 protected override CreateParams CreateParams { get ...
- laravel框架查看执行过的sql语句
1.在routes.php中添加如下语句 Event::listen('illuminate.query', function($sql,$param) { file_put_contents ...
- linux查找yum和rpm安装路径
linux查找yum和rpm安装路径 转:https://jingyan.baidu.com/article/86112f1378bf282737978730.html
- unity free asset
Unity Test Tools https://www.assetstore.unity3d.com/#/content/13802 Sample Assets (beta) https://www ...
- SVN常见问题(转)
svn常见问题,报错,命令及我的总结 (2013-07-19 18:07:27) 转载▼ 我自己犯过的一个错误是:/svn/MyERP_core_Main/!svn/act/b8bd621b- ...