题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不错,思路很好 #include <iostream> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <memory>…
题目 #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…
<题目链接> 题目大意: 裸的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&…
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…
题目链接: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 =…
题目传送门 题意: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&…
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…
一.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://blog.csdn.net/u012860063 题目链接:id=3903">http://poj.org/problem?id=3903 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…