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 ...
随机推荐
- 使用InstallUtil对Windows服务进行安装与卸载
关于Visual Studio 2012中使用InstallUtil对Windows服务进行安装与卸载的文章,在MSDN中的http://msdn.microsoft.com/en-us/librar ...
- Linux学习笔记 (四)归档和压缩
一.zip压缩命令: 1.压缩文件: 格式:zip 压缩文件 源文件 例:zip abc.zip abc //将abc文件压缩到abc.zip文件内. 2.压缩目录: 格式:zip –r 压缩目录 ...
- Zigbee事件
ZIGBEE事件有两类.系统定义事件和用户定义事件. 系统类事件是协议栈已定义好的.用户类事件是我们用户层面来定义的. 事件类号採用一个16bit的常量,使用独热码编码,独热码是仅仅有一个bit为1, ...
- $ gulp watch 运行出错解决方法
$ gulp watch 运行出错解决方法 $ gulp watch 如果你出现了如下报错信息: gulp-notify: [Laravel Elixir] Browserify Fail ...
- svn上检出的项目在myeclipse中报错的解决
项目本身应该是没问题的,应该是验证方面导致的错误的报错,取消验证即可:右键项目,如下操作: 除此之外,还应考虑是否环境问题引起的报错,比如:项目jar包是否发布,jdk的版本,tomcat的版本,等等
- NSTimer 增加引用计数, 导致内存泄露,
self.adTimer = [NSTimerscheduledTimerWithTimeInterval:5.0target:selfselector:@selector(handleADIma ...
- "《 Serial Drivers 》by Alessandro Rubini" 学习笔记
Introduction to "serial device driver" (My study note) 膜拜大神的作品. Standing on the should ...
- java 图片缩放
使用java自带的图片处理api,也可以使用(GraphicsMagick + im4j) import java.awt.Image; import java.awt.image.BufferedI ...
- Atitit.播放系统规划新版本 and 最近版本回顾 v3 pbf.doc
Atitit.播放系统规划新版本 and 最近版本回顾 v3 pbf.doc 1 版本11 (ing)4 1.1 规划h5本地缓存系列 4 1.2 Android版本app4 1.3 双类别系统, ...
- [转载]linux下svn命令使用大全
原文地址:http://blog.chinaunix.net/uid-22150747-id-189264.html 最近经常使用svn进行代码管理,这些命令老是记不住,得经常上网查,终于找了一个li ...