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

题意:两题意思差不多,都是给你一个序列,然后求最少需要改变多少个数字,使得成为一个最长不升,或者最长不降子序列. 当然3671是只能升序,所以更简单一点. 然后就没有什么了,用二分的方法求LIS即可. 贴一下3670,3671几乎没变化,只需将求最长不升的那部分去掉即可. #include <set> #include <map> #include <stack> #include <cmath> #include <queue> #includ…
权值为1~3 好了 此题是水题-- i表示到了第i个数,j表示结尾的数是j f[i][j]=min(f[i][j],f[i-1][k]+(a[i]!=j)) 1<=k<=j 最长上升的. 同理我们可以再写一个g[i][j]表示最长下降的 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,a[33333],f[3…
// 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…
题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <s…
Description The cows are so very silly about their dinner partners. They have organized themselves into three groups (conveniently numbered 1, 2, and 3) that insist upon dining together. The trouble starts when they line up at the barn to enter the f…
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值.. 注意一点,有可能最中间的值重复,也有可能不重复,所以要考虑这两种情况:(假设中点为K) 1)不重复的情况,求LIS(K) + LDS(K+1)的最大值 2)重复的情况,这时K既包含在LIS当中,也包含在LDS中,计算了两次,最终结果要减掉1 复杂度:O(n^2) 代码: #include <io…
pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. Sample Input 6 5 2 1 4 5 3 3 1 1 1 4 4 3 2 1Sample Output 3 1 1 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath…
本题就是一题LIS(最长递增子序列)的问题.本题要求求最长递增子序列和最长递减子序列. dp的解法是O(n*n),这个应该大家都知道.只是本题应该超时了. 由于有O(nlgn)的解法. 可是因为本题的数据特殊性.故此本题能够利用这个特殊性加速到O(n)的解法.当中的底层思想是counting sort分段的思想.就是假设你不会counting sort的话,就非常难想出这样的优化的算法了. O(nlgn)的利用单调队列性质的解法,利用二分加速是有代表性的,无数据特殊的时候也能够使用.故此这里先给…
Eating Together Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5579   Accepted: 2713 Description The cows are so very silly about their dinner partners. They have organized themselves into three groups (conveniently numbered 1, 2, and 3…
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) 的数字序列, 要你求该序列中的最长(严格)下降子序列的长度. 分析:        读取全部输入, 将原始数组逆向, 然后求最长严格上升子序列就可以. 因为n的规模达到20W, 所以仅仅能用O(nlogn)的算法求.        令g[i]==x表示当前遍历到的长度为i的全部最长上升子序列中的最小序列末…