由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 最长递增子array的算法
相关主题
career cup book v4 9.7 题请教一个常见的面试题的答案
fb电面第一轮Maximum Contiguous Subarray
问一道面试题max sub vector sum 问题
一道 facebook 电面题programming pears上的maximum subarray算法是不是有小bug?
狗家 题 讨论Maximum Sum of Increasing Sequence
问个算法题5面试题count # of increasing subsequences of String求解
这个怎么弄?其实我很想知道, 多少软工能45分钟内把quicksort写下来
求Longest_Increasing_Subsequence JAVA O(nlgn) 代码careerup 150 上一道题 答案没看懂?
相关话题的讨论汇总
话题: ai话题: maxsofar话题: problem话题: 算法
进入JobHunting版参与讨论
1 (共1页)
t*****j
发帖数: 1105
1
一个array里面,求最长递增子array的算法,除了careerup里面答案给
树的算法以外,还有没有其他更好的算法了?谢谢!
a****n
发帖数: 1887
2
连续的还是不连续的?
Refer to: Longest increasing subsequence & Dynamic Programming
t*****j
发帖数: 1105
3
不连续的....如果是连续的话很简单吧,两个指针不就够了?

【在 a****n 的大作中提到】
: 连续的还是不连续的?
: Refer to: Longest increasing subsequence & Dynamic Programming

a****n
发帖数: 1887
t*****j
发帖数: 1105
f****g
发帖数: 313
6
Refer the "Program Pearl" Chapter 8.
The whole chapter is about how to approach this problem. It gives 4
solutions from O(n^3) to O(n).
c******a
发帖数: 789
7
There's also an O(nlogn) solution based on some observations. Let A{i,j} be
the smallest possible tail out of all increasing subsequences of length j
using elements {a1, a2, a3, ..., ai}.
Observe that, for any particular i, A{i,1} < A{i,2} < ... < A{i,j}. This suggests that if we want the longest subsequence that ends with a i + 1, we only need to look for a j such that Ai,j < ai + 1 < = Ai,j + 1 and the length will be j + 1.
Notice that in this case, Ai + 1,j + 1 will be equal to ai + 1, and all Ai +1,k will be equal to Ai,k for k != (j + 1).
Furthermore, there is at most one difference between the set Ai and the set Ai + 1, which is caused by this search.
Since A is always ordered in increasing order, and the operation does not change this ordering, we can do a binary search for every single a1, a2,..., an.
i,j都是小字体,唉,凑合着看吧。
E********a
发帖数: 124
8
just search LIS on wiki
c******a
发帖数: 789
p********7
发帖数: 549
10
我觉得不可能是O(N),最佳是N*logN

【在 f****g 的大作中提到】
: Refer the "Program Pearl" Chapter 8.
: The whole chapter is about how to approach this problem. It gives 4
: solutions from O(n^3) to O(n).

t*****j
发帖数: 1105
11
我也这么觉得,不过还没时间看那个算法。
这么多热心人....谢谢啊!

【在 p********7 的大作中提到】
: 我觉得不可能是O(N),最佳是N*logN
f****g
发帖数: 313
12
I check the book again, and the best algorithm is in O(n), haha
Here is the pseudo code copied from "Programming Pearl"
maxsofar = 0;
maxendinghere = 0;
for i = [0,n)
maxendinghere = max(maxendinghere + x[i], 0)
maxsofar = max(maxsofar, maxendinghere)
the run time is O(n). It is DP problem.
Let me know if you still have any question about it:S

【在 p********7 的大作中提到】
: 我觉得不可能是O(N),最佳是N*logN
z****n
发帖数: 1379
13
。。。这个是和最大的连续子集。。。
那个是最常递增子序列

【在 f****g 的大作中提到】
: I check the book again, and the best algorithm is in O(n), haha
: Here is the pseudo code copied from "Programming Pearl"
: maxsofar = 0;
: maxendinghere = 0;
: for i = [0,n)
: maxendinghere = max(maxendinghere + x[i], 0)
: maxsofar = max(maxsofar, maxendinghere)
: the run time is O(n). It is DP problem.
: Let me know if you still have any question about it:S

f****g
发帖数: 313
14
you are right:D, and I am just thinking completely different problem :(
I like the following solution a lot, and it reconstructs the problem as a directed graph
, very simple and straightforward :D
http://www.cs.berkeley.edu/~vazirani/algorithms/chap6.pdf

【在 z****n 的大作中提到】
: 。。。这个是和最大的连续子集。。。
: 那个是最常递增子序列

1 (共1页)
进入JobHunting版参与讨论
相关主题
careerup 150 上一道题 答案没看懂?狗家 题 讨论
再来一道简单的bit运算题问个算法题5
谁能解释下careerUp上18.3这题吗?这个怎么弄?
Random Array number, Find longest consecutive sequence求Longest_Increasing_Subsequence JAVA O(nlgn) 代码
career cup book v4 9.7 题请教一个常见的面试题的答案
fb电面第一轮Maximum Contiguous Subarray
问一道面试题max sub vector sum 问题
一道 facebook 电面题programming pears上的maximum subarray算法是不是有小bug?
相关话题的讨论汇总
话题: ai话题: maxsofar话题: problem话题: 算法