题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列。

当然3671是只能升序,所以更简单一点。

然后就没有什么了,用二分的方法求LIS即可。

贴一下3670,3671几乎没变化,只需将求最长不升的那部分去掉即可。

#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Max 2505
#define FI first
#define SE second
#define ll long long
#define PI acos(-1.0)
#define inf 0x3fffffff
#define LL(x) ( x << 1 )
#define bug puts("here")
#define PII pair<int,int>
#define RR(x) ( x << 1 | 1 )
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
using namespace std; int a[33333] ;int n ;
int qe[33333] ;
int LIS(int *x ){
int head = 0 ;mem(qe ,0) ;
for (int i = 0 ; i < n ; i ++ ){
if(head == 0 || x[i] >= qe[head]){
qe[++ head] = x[i] ;
}
else {
int r = head , l = 1 ;
while(r >= l){
int mid = l + r >> 1 ;
if(qe[mid] <= x[i])l = mid + 1 ;
else r = mid - 1 ;
}
qe[l] = x[i] ;
}
}
return head ;
}
int main() {
cin >> n ;
for (int i = 0 ; i < n ; i ++ ){
scanf("%d",&a[i]) ;
}
int x = LIS(a) ;
reverse(a , a + n) ;
int y = LIS(a) ;
cout << n - max(x , y) << endl;
return 0;
}

POJ 3670 , 3671 LIS的更多相关文章

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

  2. poj 3670(LIS)

    // File Name: 3670.cpp // Author: Missa_Chen // Created Time: 2013年07月08日 星期一 21时15分34秒 #include < ...

  3. POJ 3670 Eating Together (DP,LIS)

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

  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 Alignment --LIS&LDS

    题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...

  6. poj 3903 poj 2533 (LIS模板题)

    pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. Sample Input 6 5 2 1 4 5 3 3 1 1 1 ...

  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 1887 Testingthe CATCHER (LIS:最长下降子序列)

    POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...

随机推荐

  1. IDEA 整合Junit实现自动生成测试代码

    1.安装插件 junit generator 重启IDEA,完成安装. 2. 选中需要测试的方法,按alt + insert 即可自动生成测试类\方法 3. 设置

  2. UVA 11090 Going in Cycle!!

    要求给定的图的中平均权值最小的环,注意处理自环的情况就能过了. 按照w1+w2+w3+….wn < n*ave的不等式,也就是(w1-ave) + (w2-ave) +…..(wn-ave) & ...

  3. [jobdu]数组中的逆序对

    http://ac.jobdu.com/problem.php?pid=1348 数组中的逆序对也是个常见的题目,算法导论中也有一些描述,参考:http://www.cnblogs.com/wuyue ...

  4. [cocos2dx 3.x]Label类数字变化动作

    之前写了个2.14版本的动作变化,见 http://www.cnblogs.com/creeper/p/3531304.html 3.x版本变化了很多,但是核心思想还是没有变化,所以对应3.x版本的改 ...

  5. JAVA与C++的区别和联系

    这篇总结的貌似不错: http://wenku.baidu.com/link?url=VixkWGl0BzUkmceaDJnQeUhzKEIex6poGaKKvMTP87P8a7HTmS5uIi87I ...

  6. 【HDOJ】1720 A+B coming

    水题. #include <stdio.h> #include <string.h> #define MAXNUM 1005 int stoi(char); int main( ...

  7. CH Round #17 舞动的夜晚

    舞动的夜晚 CH Round #17 描述 L公司和H公司举办了一次联谊晚会.晚会上,L公司的N位员工和H公司的M位员工打算进行一场交际舞.在这些领导中,一些L公司的员工和H公司的员工之间是互相认识的 ...

  8. 数学物理学报Offprints and Remuneration

  9. Mysql监控工具小集合

    介绍一些常见的Mysql监控工具. Cacti Cacti是 一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.它通过snmpget来获取数据,使用 RRDtool绘 ...

  10. 通过Java SE 7自带的监控服务(WatchService API)实现类似.NET FileWatcher的功能

    Java SE 7 Tutorial中增加了一个监控目录变更情况的示例,用于介绍其新发布的WatchService API. 但对于用惯了.NET FileWatcher的用户而言,如果用于项目我认为 ...