一.Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called the CATCHER which is capable of intercepting multiple incoming offensive missiles. The CATCHER is su…
Language: Default Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15207   Accepted: 5595 Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defen…
Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13396   Accepted: 4905 Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile calle…
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called th…
题意:题目太长没看,直接看输入输出猜出是最长下降子序列 用了以前的代码直接a了,做法类似贪心,把最小的顺序数存在数组里面,每次二分更新数组得出最长上升子序列 #include<iostream> #include<cstdio> using namespace std; int main() { int dp[40002],a[40002],n,t,i,low,up,top,mid,max,tmp,k,b[40002],cas=1; while(1) { scanf("%…
题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木棍的最少时间. 分析: 1.将木棍按l排序后,实质上是求按w形成的序列中的最长递减子序列. eg: 5 4 9 5 2 2 1 3 5 1 4 将木棍按l排序后,按w形成的序列为4 1 5 9 2, 则若按照4 5 9 1 2的顺序安装(按照木棍标号为1 3 4 2 5的顺序安装),只需两分钟. 容易发现,所…
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) 的数字序列, 要你求该序列中的最长(严格)下降子序列的长度. 分析:        读取全部输入, 将原始数组逆向, 然后求最长严格上升子序列就可以. 因为n的规模达到20W, 所以仅仅能用O(nlogn)的算法求.        令g[i]==x表示当前遍历到的长度为i的全部最长上升子序列中的最小序列末…
Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16131   Accepted: 5924 Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile calle…
Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13968   Accepted: 5146 Description A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile calle…
lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int solve(int x) { ,b=res; while(a!=b) { ; if(lis[mid]>=x) b=mid; else a=mid+; } return a; } int main() { int n; cin>>n; ;i<=n;i++) scanf("%d&…
Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of two functional blo…
E - LIS Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned a…
Description A numeric sequence of ai is ordered ifa1 <a2 < ... < aN. Let the subsequence of the given numeric sequence (a1,a2, ..., aN) be any sequence (ai1,ai2, ..., aiK), where 1 <=i1 < i2 < ... < iK <=N. For example, sequence (1…
题意:求最大上升子序列 思路:才发现自己不会LIS,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚看了LIS的nlogn写法(贪心+二分):维护一个dp[i]表示最大长度为i时的最小结尾,初始memset为INF,最终dp数组的长度为答案.这个很好维护,如果当前的a[i]比dp[len]要大,那么显然最大长度加一,dp[len + 1] = a[i]:如果比dp[len]小,那么我就去二分查找前…
一.Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking f…
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack&…
题意:求二维偏序的最少链划分. 用到Dilworth定理:最少链划分=最长反链.(对偶也成立,个人认为区别只是一个维度上的两个方向,写了个简单的证明 相关概念:偏序集,链,反链等等概念可以参考这里:http://www.cnblogs.com/fstang/archive/2013/03/31/2991220.html Dilworth定理的证明(英文的):http://aleph.math.louisville.edu/teaching/2009FA-681/notes-091119.pdf…
Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10762   Accepted: 5899 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers…
题目大意:一种拦截导弹能拦截多枚导弹,但是它在每次拦截后高度不会再升高,给出导弹的序列,问最多能拦截多少枚导弹? 最长递减子序列问题. #include <cstdio> #include <vector> #include <algorithm> using namespace std; vector<int> m, lds; int main() { #ifdef LOCAL freopen("in", "r",…
题目链接 最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列. #include <iostream> #include <algorithm> using namespace std; ; int s[N],x; int main() { int n; while(cin>>n){ ; ;i<n;i++){ cin>>x; ||s[top-]<x) s[top++]=x; else s[upper_bound(s,s+top,…
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…
题目链接:http://acm.swust.edu.cn/problem/585/ Time limit(ms): 3000 Memory limit(kb): 65535   SWUST国的一支科学考察队到达了举世闻名的古埃及金字塔. 关于金字塔的建造一直是一个未解之谜, 有着“西方史学之父”之称的希罗多德认为,金字塔的建造是人力和牲畜,花费20 年时间从西奈半岛挖掘天然的石头运送到埃及堆砌而成.也有不少人认为是外星人修建的.人们发现胡夫金字塔的经线把地球分成东.西两个半球,它们的陆地面积是相…
转载自:最长上升子序列(LIS)长度的O(nlogn)算法 最长上升子序列nlogn算法 在川大oj上遇到一道题无法用n^2过于是,各种纠结,最后习得nlogn的算法 最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS.排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个序列d[1..9] = 2 1 5 3 6 4 8 9 7,可以看出来它的LIS长度为5.n下面一步一步试着找出它.我们定义一个序列B,然后令 i = 1…
2017-09-10 16:51:03 writer:pprp 严格递增的LIS模板 #include<stdio.h> #include<string.h> #include<algorithm> #include <vector> #include <iostream> using namespace std; ] = {,,,,,}; vector<int> v; int main() { v.clear(); v.push_b…
1.LIS : 给定一个序列,求它的最长上升子序列(n<=2000) 第一种 O(n^2): dp[i] 为以i为开头的最长上升子序列长度 code1: #include<cstdio> #include<iostream> using namespace std; int n,ans; int a[2005],dp[2005]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf…
二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound()的主要区别在于前者返回第一个大于目标值的位置 int lowerBound(int x){ int l=1,r=n; while(l<=r){ int mid=(l+r)>>1; if (x>g[mid]) l=mid+1; else r=mid-1; } return l; } in…
LIS问题 https://www.acwing.com/problem/content/898/ 思路:首先数组a中存输入的数(原本的数),开辟一个数组f用来存结果,最终数组f的长度就是最终的答案:假如数组f现在存了数,当到了数组a的第i个位置时,首先判断a[i] > f[cnt] ? 若是大于则直接将这个数添加到数组f中,即f[++cnt] = a[i];这个操作时显然的.当a[i] <= f[cnt] 的时,我们就用a[i]去替代数组f中的第一个大于等于a[i]的数,因为在整个过程中我们…
In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are…
题目大意:有n*n个方格,王子有一条走法,依次经过m个格子,公主有一种走法,依次经过n个格子(不会重复走),问他们删去一些步数后,重叠步数的最大值. 显然是一个LCS,我一看到就高高兴兴的打了个板子上去,结果TLE+RE. 仔细一看:n<=250,那么二维数组就得开250*250*250*250了,显然RE了. 所以我想着用滚动数组来存储,但是TLE又拦住了我的去路. O(n^2)的效率就是62500*62500,大于10^8,所以1s之内完不成,所以要想别的办法. 偶然在网上找到了O(nlog…
单调递增最长子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4   输入 第一行一个整数0<n<20,表示有n个字符串要处理随后的n行,每行有一个字符串,该字符串的长度不会超过10000 输出 输出字符串的最长递增子序列的长度 样例输入 3 aaa ababc abklmncdefg 样例输出 1 3 7 [分析] [代码] #include <cstdio>…