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 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,用线段树写的,也没说数据范围就写了个离散化,每次查找以1~a[i]-1结尾的最大序列答案,然后更新,这样遍历一遍就行了.最近代码总是写残啊... 刚看了LIS的nlogn写法(贪心+二分):维护一个dp[i]表示最大长度为i时的最小结尾,初始memset为INF,最终dp数组的长度为答案.这个很好维护,如果当前的a[i]比dp[len]要大,那么显然最大长度加一,dp[len + 1] = a[i]:如果比dp[len]小,那么我就去二分查找前…
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…
题目传送门 题意: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&…
题目链接: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 =…
题目 #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&…
Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2954   Accepted: 1082 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…