// 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)的更多相关文章

  1. POJ 3670 , 3671 LIS

    题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列. 当然3671是只能升序,所以更简单一点. 然后就没有什么了,用二分的方法求LIS即可. ...

  2. POJ 3670 Eating Together (DP,LIS)

    题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #inclu ...

  3. 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 最长上升的. ...

  4. POJ 3670 Eating Together(LIS)

    Description The cows are so very silly about their dinner partners. They have organized themselves i ...

  5. poj 1836 LIS变形

    题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submiss ...

  6. poj 1631 LIS

    题目链接:http://poj.org/problem?id=1631 #include <cstdio> #include <cstring> #include <io ...

  7. POJ 3670 Eating Together 二分解法O(nlgn)和O(n)算法

    本题就是一题LIS(最长递增子序列)的问题.本题要求求最长递增子序列和最长递减子序列. dp的解法是O(n*n),这个应该大家都知道.只是本题应该超时了. 由于有O(nlgn)的解法. 可是因为本题的 ...

  8. E-Eating Together(POJ 3670)

    Eating Together Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5579   Accepted: 2713 D ...

  9. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

随机推荐

  1. 转:http2基本中文翻译

    https://github.com/fex-team/http2-spec/blob/master/HTTP2%E4%B8%AD%E8%8B%B1%E5%AF%B9%E7%85%A7%E7%89%8 ...

  2. CentOS7安装Gnome GUI图形界面

    CentOS7安装Gnome GUI图形界面  最小化安装了.当时没 注意,后面一步步安装完了,结果直接启动到命令行模式了. 晕,又不想重新安装,直接想从命令行模式安装.在网上找了半天,终于找到一点小 ...

  3. [Functional Programming] Draw Items from One JavaScript Array to Another using a Pair ADT

    We want to be able to pick nine random cards from an array of twelve cards, but can run into problem ...

  4. 播放器设置 Player Settings

    原地址:http://game.ceeger.com/Manual/class-PlayerSettings.html#Android Player Settings is where you def ...

  5. 神奇的canvas——巧用 canvas 为图片添加水印

    代码地址如下:http://www.demodashi.com/demo/11637.html 很久之前写过一篇关于 canvas 的文章,是通过 canvas 来实现一个绚丽的动画效果,不管看过没看 ...

  6. linux如何手动释放linux内存

    当在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都没有看到有什么很好解决的办法.那么我来谈谈这个问题 ...

  7. Jenkins spring boot 自动部署方案

    原文地址:http://www.cnblogs.com/skyblog/p/5632869.html 现在主流的自动部署方案大都是基于Docker的了,但传统的自动部署方案比较适合中小型公司,下面的方 ...

  8. JS防后退跳转

    location.replace("http://www.baidu.com");

  9. chrome 浏览器 的一些控制台技巧

    1.查找dom元素.但它并不支持jquery语法. $$("#fock");   // 目前仅仅知道可以查找Dom元素 2.查找dom元素绑定的事件. getEventListen ...

  10. vc2010, fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt解决办法

    是因为安其它软件的时候更新了.net framework,导致vc2010出了问题. 解决办法是在系统里搜索cvtres.exe,会搜到很多,把其中 Microsoft Visual Studio 1 ...