greedy

Dynamic vs Greedy Algorithms : The debate regarding Neil G's answer on the same topic

南笙酒味 提交于 2019-12-24 03:38:50
问题 I was trying to understand the differences between Dynamic and Greedy algorithms, and This answer by Neil G was quite helpful, but, there was this one statement that he made which caused a debate in the comments section. The difference between dynamic programming and greedy algorithms is that with dynamic programming, the subproblems overlap. That means that by "memoizing" solutions to some subproblems, you can solve other subproblems more quickly. Comments aren't the best place to solve a

regex c# optional group - should act greedy?

此生再无相见时 提交于 2019-12-24 02:48:36
问题 having regex ~like this: blablabla.+?(?:<a href="(http://.+?)" target="_blank">)? I want to capture an url if I find one... finds stuff but I don't get the link (capture is always empty). Now if I remove the question mark at the end like this blablabla.+?(?:<a href="(http://.+?)" target="_blank">) This will only match stuff that has the link at the end... it's 2.40 am... and I've got no ideas... --Edit-- sample input: blablabla asd 1234t535 <a href="http://google.com" target="_blank">

regex c# optional group - should act greedy?

北城余情 提交于 2019-12-24 02:48:11
问题 having regex ~like this: blablabla.+?(?:<a href="(http://.+?)" target="_blank">)? I want to capture an url if I find one... finds stuff but I don't get the link (capture is always empty). Now if I remove the question mark at the end like this blablabla.+?(?:<a href="(http://.+?)" target="_blank">) This will only match stuff that has the link at the end... it's 2.40 am... and I've got no ideas... --Edit-- sample input: blablabla asd 1234t535 <a href="http://google.com" target="_blank">

Finding an increasing sequence a[] which minimizes sigma(abs(a[i]+c[i]))

倖福魔咒の 提交于 2019-12-23 13:14:06
问题 Problem statement c is a given array of n integers; the problem is to find an increasing array of n integers a (a[i] <= a[i+1]) such that this sum is minimized: abs(a[0]+c[0]) + abs(a[1]+c[1]) + ... + abs(a[n-1]+c[n-1]) // abs(x) = absolute value of x An optimal a exists only made by integers appeared in c so we can solve it using DP in O(n^2) : dp[i][j]: a[i] >= j'th integer But there should be a faster solution, probably O(n lg n) . 回答1: Update: I add the solution, which minimizes sum-of

Greedy algorithm: Interval coloring

让人想犯罪 __ 提交于 2019-12-23 11:57:06
问题 In interval scheduling, the algorithm is to pick the earliest finish time. But in interval colouring the former does not work. Is there an example or explanation on why picking earliest finish time won't work for interval colouring? The interval colouring problem is: 
given
 a 
set 
of 
intervals,
 we 
want 
to 
colour all
 intervals
 so 
that 
intervals
 given
 the
 same
 colour
 do 
not 
intersect
 and 
the
goal
 is 
to 
try 
to
 minimize 
the 
number 
of 
colours 
used. This can be thought

Greedy algorithm: Interval coloring

有些话、适合烂在心里 提交于 2019-12-23 11:56:16
问题 In interval scheduling, the algorithm is to pick the earliest finish time. But in interval colouring the former does not work. Is there an example or explanation on why picking earliest finish time won't work for interval colouring? The interval colouring problem is: 
given
 a 
set 
of 
intervals,
 we 
want 
to 
colour all
 intervals
 so 
that 
intervals
 given
 the
 same
 colour
 do 
not 
intersect
 and 
the
goal
 is 
to 
try 
to
 minimize 
the 
number 
of 
colours 
used. This can be thought

Activity selection greedy approach (modified) [duplicate]

馋奶兔 提交于 2019-12-22 18:18:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Algorithm to find the maximum sum in a sequence of overlapping intervals I was solving the following modified activity scheduling (Greedy approach) problem : Given a set S of n activities with and start time, Si and fi , finish time of an ith activity. Also given weight wi , the cost earned by Foo for doing ith activities . The problem is to select the activities that maximizes foo earnings . We have to return

lookahead in kate for patterns

删除回忆录丶 提交于 2019-12-21 22:54:23
问题 I'm working on compiling a table of cases for a legal book. I've converted it to HTML so I can use the tags for search and replace operations, and I'm currently working in Kate. The text refers to the names of cases and the citations for the cases are in the footnotes, e.g. <i>Smith v Jones</i>127 ......... [other stuff including newline characters].......</br>127 (1937) 173 ER 406; I've been able to get lookahead working in Kate, using: <i>.*</i>([0-9]{1,4}) .+<br/>\1 .*<br/> ...but I've run

Point covering problem

爷,独闯天下 提交于 2019-12-20 10:47:14
问题 I recently had this problem on a test: given a set of points m (all on the x-axis) and a set n of lines with endpoints [ l, r ] (again on the x-axis), find the minimum subset of n such that all points are covered by a line. Prove that your solution always finds the minimum subset. The algorithm I wrote for it was something to the effect of: (say lines are stored as arrays with the left endpoint in position 0 and the right in position 1) algorithm coverPoints(set[] m, set[][] n): chosenLines =

Matching text between delimiters: greedy or lazy regular expression?

会有一股神秘感。 提交于 2019-12-20 09:37:26
问题 For the common problem of matching text between delimiters (e.g. < and > ), there's two common patterns: using the greedy * or + quantifier in the form START [^END]* END , e.g. <[^>]*> , or using the lazy *? or +? quantifier in the form START .*? END , e.g. <.*?> . Is there a particular reason to favour one over the other? 回答1: Some advantages: [^>]* : More expressive. Captures newlines regardless of /s flag. Considered quicker, because the engine doesn't have to backtracks to find a