POJ 3670 , 3671 LIS
题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列。
当然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的更多相关文章
- 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(LIS)
// File Name: 3670.cpp // Author: Missa_Chen // Created Time: 2013年07月08日 星期一 21时15分34秒 #include < ...
- POJ 3670 Eating Together (DP,LIS)
题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #inclu ...
- POJ 3670 Eating Together(LIS)
Description The cows are so very silly about their dinner partners. They have organized themselves i ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- 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 ...
- 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 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
随机推荐
- OCR识别流程
1.图像输入.预处理:图像输入:对于不同的图像格式,有着不同的存储格式,不同的压缩方式.预处理:主要包括二值化,噪声去除,倾斜较正等2.二值化:对摄像头拍摄的图片,大多数是彩色图像,彩色图像所含信息量 ...
- input checkbox问题和li里面包含checkbox
<input type="checkbox" id="checkbox1"/> $("input#checkbox1").cli ...
- bzoj2716
感人肺腑pascal过不去系列(可能是自己弱,因为有pascal过去了毕竟)那个这种平面点还有一种处理方法是kd tree,太弱了不会有时间学一下我还是用了cdq分治,首先肯定要把绝对值这个不和谐的东 ...
- Mac 上Dock中添加“最近打开过的项目”(Recent Applications)
有一个特别有用的Stack,“最近打开过的项目”,建立方法如下: 1. 打开Terminal,输入以下命令 defaults write com.apple.dock persistent-other ...
- C# 多线程(lock,Monitor,Mutex,同步事件和等待句柄)
本篇从 Monitor,Mutex,ManualResetEvent,AutoResetEvent,WaitHandler 的类关系图开始,希望通过本篇的介绍能对常见的线程同步方法有一个整体的认识,而 ...
- ActiveX添加测试工程, 出现的问题[非选择性参数][找不到成员]
ActiveX 添加测试工程 1.新建工程MFC application, 2.添加完毕,在main Dialog中, 右键[Insert Activex Control],选择你的ActiveX控件 ...
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
最近在学习RxJava 感觉很happy ,happy的同时遇到不少问题 没办法一点一点来 上张帅图先 在使用RxJava + Retrofit 的时候 有时候接口请求参数不规范 比如 {} @For ...
- lightoj 1002
最短路的变形,使用spfa做. #include<set> #include<map> #include<list> #include<stack> # ...
- 【转】CUDA5/CentOS6.4
转载自http://wenzhang.baidu.com/article/view?key=076f36658dd0828c-1393896446 This article explains how ...
- 判断两棵树是否相等 leecode
很简单 提交代码 https://oj.leetcode.com/problems/same-tree/ iven two binary trees, write a function to chec ...