I'm trying to find an algorithm to find K
disjoint, contiguous subsets of size L
of an array x
of real numbers that maximize the sum of the elements.
Spelling out the details, X is a set of N positive real numbers:
X={x[1],x[2],...x[N]} where x[j]>=0 for all j=1,...,N.
A contiguous subset of length L called S[i]
is defined as L consecutive members of X starting at position n[i]
and ending at position n[i]+L-1
:
S[i] = {x[j] | j=n[i],n[i]+1,...,n[i]+L-1} = {x[n[i]],x[n[i]+1],...,x[n[i]+L-1]}.
Two of such subsets S[i]
and S[j]
are called pairwise disjoint (non-overlapping) if |n[i]-n[j]|>=L
. In other words, they don't contain any identical members of X.
Define the summation of the members of each subset:
SUM[i] = x[n[i]]+x[n[i]+1]+...+x[n[i]+L-1];
The goal is find K contiguous and disjoint(non-overlapping) subsets S[1],S[2],...,S[K]
of length L such that SUM[1]+SUM[2]+...+SUM[K]
is maximized.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…