最长上升子序列(LIS)的典型变形,熟悉的n^2的动归会超时。LIS问题可以优化为nlogn的算法。定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元素。注意d中元素是单调递增的,下面要用到这个性质。首先len = 1,d[1] = a[1],然后对a...
分类:
编程语言 时间:
2014-10-21 16:56:30
阅读次数:
358
模板题,唯一问题是当长度为1是,road是单数,不然road是复数roads。
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1021000;
struct node
{
int r;
int b...
分类:
其他好文 时间:
2014-10-19 17:07:26
阅读次数:
206
4Clojure上的一道题:[4Clojure 最长上升子序列算法][1] 描述如下: > Given a vector of integers, find the longest consecutive sub-sequence of increasing numbers. If two sub-sequences have the same le...
分类:
编程语言 时间:
2014-10-18 09:55:22
阅读次数:
259
Longest Ordered Subsequence
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 33943
Accepted: 14871
Description
A numeric sequence of ai is ordered if a1 a2 ...
分类:
其他好文 时间:
2014-10-16 19:38:32
阅读次数:
209
Alignment
Time Limit: 1000MS
Memory Limit: 30000K
Total Submissions: 13319
Accepted: 4282
Description
In the army, a platoon is composed by n soldiers. During the morni...
分类:
其他好文 时间:
2014-10-16 18:04:03
阅读次数:
252
最长上升子序列LIS问题属于动态规划的初级问题,用纯动态规划的方法来求解的时间复杂度是O(n^2)。但是如果加上二叉搜索的方法,那么时间复杂度可以降到nlog(n)。 具体分析参考:http://blog.chinaunix.net/uid-26548237-id-3757779.html 代...
分类:
其他好文 时间:
2014-10-05 22:41:09
阅读次数:
194
题目地址:http://acdream.info/problem?pid=1216
这题一开始用的是线段树,后来发现查询的时候还需要DP处理,挺麻烦。。也就不了了之了。。后来想到,这题其实就是一个二维的最长上升子序列。。
要先排序,先按左边的数为第一关键字进行升序排序,再按右边的数为第二关键字进行降序排序。这样的话,第一关键字相同的的肯定不在一个同一个上升子序列中。然后只对第二关键字进行复杂度...
分类:
其他好文 时间:
2014-10-03 11:26:14
阅读次数:
195
G - Beautiful People
Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Special Judge
SubmitStatus
Problem Description
The most prestigious sport...
分类:
其他好文 时间:
2014-10-02 09:47:52
阅读次数:
181
Beautiful PeopleSpecial JudgeTime Limit:10000/5000MS (Java/Others)Memory Limit:128000/64000KB (Java/Others)SubmitStatisticNext ProblemProblem Descript...
分类:
其他好文 时间:
2014-10-01 23:27:01
阅读次数:
276
题意:
给x、y、k,在[x,y] 范围内最长上升子序列长度是k的数有几个
思路:
模仿 LIS nlogn的想法,这里就只有10个数,进行状压
然后直接搜就好了不用二分
然后按位dp下去就ok了!
代码:
#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#inc...
分类:
其他好文 时间:
2014-09-26 13:43:18
阅读次数:
213