Suppose I have an array containing nintegers.
How to find a subset of size k, so that the distance minimumbetween all pairs of integers in the subset maximized, I mean that they are at the farthest distance.
Example array a[]={1,2,6,7,10}and k=3,
subset = {1,6,10}the minimum distance 4between 10 and 6.
Irregular subsets :
{1,7,10}the minimum distance 3
{1,2,6}, the minimum distance1
I came up with a solution:
1) sort the array
2) select [0], now find ceil (a [0] + x) = Y in the array .... and then ceil (Y + x), etc. k-1times, also the kth element will bea[n-1]
Find x:
dp[i,j]will be xto select j elements from the first i elements.
Finally, we want dp[n][k]whichx
But I ran into a search problem x.
dp [i, j] = max (min (dp [k, j-1], dp [i] -A [k]))
over k = 1 - i-1, i = 2 - n, j = 2 - i
dp [i] [1] = 0 over i = 1 to n
EDIT . I want to fix a dynamic programming solution , although I know that x can be detected by binary search on x.
2. , . .
: http://ideone.com/J5vvR9
3: @Gassa, @Niklas B. @Fallen !