// 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. [ACM] POJ 2151 Check the difficulty of problems (概率+DP)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   ...

  2. RGB颜色工具大全 and 网页配色方案

    RGB颜色工具:http://www.ostools.net/commons?type=3 配色方案:http://www.wzsky.net/html/Website/Color/103380.ht ...

  3. Mycat探索之旅(5)----常用的分片规则

    分片枚举 通过在配置文件中配置可能的枚举id,自己配置分片,本规则适用于特定的场景,比如有些业务需要按照省份或区县来做保存, 而全国省份区县固定的,这类业务使用本条规则,配置如下: <table ...

  4. Splunk 会议回想: 大数据的关键是机器学习

    作者 Jonathan Allen ,译者 张晓鹏 Splunk的用户大会已经接近尾声.三天时间的会议里,共进行了160多个主题研讨.涵盖了从安全.运营到商业智能.甚至包含物联网,会议中一遍又一遍出现 ...

  5. [转]SQL Server 性能调优(io)

      目录 诊断磁盘io问题 常见的磁盘问题 容量替代了性能 负载隔离配置有问题 分区对齐配置有问题 总结 关于io这一块,前面的东西如磁盘大小,磁盘带宽,随机读取写入,顺序读取写入,raid选择,DA ...

  6. c和c++在windows下获取时间和计算时间差的方法总结

    c/c++在windows下获取时间和计算时间差的几种方法总结 一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double diff ...

  7. hdu - 4782 - Beautiful Soup(模拟)

    题意:输出一堆乱排版的html标签,去多余空字符,转换为按缩进输出. 题目链接:pid=4782">http://acm.hdu.edu.cn/showproblem.php?pid= ...

  8. Oracle表空间不足处理

    异常信息: 异常信息(异常类型:System.Data.OracleClient.OracleException) 异常提示:Oracle数据执行异常,请联系管理员处理 异常信息:ORA: 表 LC0 ...

  9. SSH——增删改的实现二

    二.批量删除 逻辑删除取派员,将取派员的deltag改为“1” 1. 为“作废”按钮绑定事件 //批量删除取派员 function doDelete(){ //获得选中的行 var rows = $( ...

  10. python with上下文的浅谈

    python中的with一般用于上下文管理,什么是上下文管理,其实平时我们经常会用到,比如连接数据库 查询数据,操作完成后关闭连接. 还比如打开文件写入数据等操作. 具体实例: class Myres ...