Re: How to find the maximum sum of atleast L consecutive integers given a sequence of N integers.



On 2006-03-20, vb@xxxxxxxxx <vb.here@xxxxxxxxx> wrote:
Hi all,

How can we find the maximum sum of atleast L consecutive integers given
a sequence of N integers.

The brute force approach of forming all possible length sequences at
every index and finding their sum gives an O(N^2) solution which is not
desirable.

Could you do something like this:

1. Create a new sequence by replacing each run of adjacent positive
integers with their sum and each run of adjacent negatives with their
sum. Also create some kind of index so that each member of the new
sequence can be mapped back to the start and end of the run it
represents in the original sequence.
2. Find the highest adjacent sum in the new (shorter) sequence
using your brute force method.
3. Using the index match this back to the original sequence. If the
length of this sequence is < L, go back to step 2 looking for the
next highest.

Just a thought, I haven't tried it.
.



Relevant Pages

  • Re: * says: Definition: sum{i in N} i = 0
    ... "Divergent series" means: ... is the sum of its terms, ... underlying infinite sequence _if_ the limit exists. ... Euler has literally written is not proved true. ...
    (sci.math)
  • Re: Synthesis of Concurrent Statements for FIR Filter
    ... the convolution in VHDL. ... and -1's and convolved with the impulse sequence 'h'. ... into sum AND THEN put the 'sum' result into 'y'. ... What you have written contains 0 multipliers, 15 x 2-1 muxes, no ...
    (comp.lang.vhdl)
  • Re: * says: Definition: sum{i in N} i = 0
    ... "Divergent series" means: ... is the sum of its terms, then you get the result that a divergent ... that the infinite sequence of naturals is divergent in N. ... _you_ impute that Euler literally has written. ...
    (sci.math)
  • Re: Tea cups and elephants
    ... the sum "in the limit" can be written as something ... infinite number of terms "in the limit". ... called the sequence of partial sums. ... that's an optical illusion. ...
    (sci.math)
  • Re: Time Reversal and Frequency Response - paper
    ... if an original time sequence is: ... The DFT of P&M's time-reversed sequence is the ... Now if you write the original sequence repetitively ...
    (comp.dsp)