题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bsearch(int a[],int len,int num) { ,right=len; while(left<=right) { ; if(num<=a[mid]) //若最长不下降子序列,改<= 为 < right=mid-; else left=mid+; } return le…
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不错,思路很好 #include <iostream> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <memory>…
<题目链接> 题目大意: 裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找. O(nlogn)算法 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; int a[N],rise[N]; int main(){ int n;while(~scanf("%d&…
POJ3903 Stock Exchange #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; ; int a[maxn]; int main() { int n; while (~scanf("%d",&n)) { ; i <= n; ++i) scanf("%d&qu…
POJ 3903    Stock Exchange  (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E 题目: Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John…
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…
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d[1~len]中二分查找第一个大于等于a[i]的位置j,使d[j]=a[i].附上打印路径代码(准确性未知) 代码: #include <cstdio> #include <algorithm> #include <cstring> #include <vector&…
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) 的数字序列, 要你求该序列中的最长(严格)下降子序列的长度. 分析:        读取全部输入, 将原始数组逆向, 然后求最长严格上升子序列就可以. 因为n的规模达到20W, 所以仅仅能用O(nlogn)的算法求.        令g[i]==x表示当前遍历到的长度为i的全部最长上升子序列中的最小序列末…
一.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…
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #include <algorithm> using namespace std; const int maxn = 100010; int n, a[maxn], f[maxn], maxlen = 0; int main() { while (cin >> n) { maxlen =…