I’ve given some intervals I = {I(1), I(2), ..., I(m)} for I(i) = [a_i, b_i] (1<=a_i<=b_i<=n). You may suppose that intervals cover each other(sorry i’m poor in english), so there’s no intervals such as {[1,5], [3,6]}, {[2,5], [5,7]}. And {[1,1], [2,2], ..., [n,n]} must be included in I.
Let’s suppose C(i) = b_i - a_i + 1.
I want to find {I(c_1), I(c_2), ..., I(c_k)} that are non overlapped by each other, and C(c_1) + C(c_2) + ... + C(c_k) = T. (1 <= T <= n).
I could find O(n*T) DP solution using Subset Sum problem, and I think it’s NP, but I’m not sure. Can I optimize more than O(n*T)?
The problem is reduceable from the Subset Sum problem (Given a set of numbers and a target number, find out if there is a subset that sums to this target) with a simple reduction:
Given an instance of subset-sum:
S={c_1,c_2,..,c_n},T– create an instance of this problem by creatingnnon overlapping intervals, interval i, withc_ipoints (easy to do by ascending order). The sameTremains.Now, the answer to the subset-sum problem is true if and only if there is a subset of intervals that sums to
T. It is basically the same problem, since all intervals do not overlap each other by definition of the problem.From this we can conclude – your problem is NP-Hard.
Moreover, if we could solve the problem better then
O(T*n), we could use the same approach to solve the subset sum problem better thenO(T*n)1,2.However, AFAIK, best pseudo polynomial solution to subset sum is
O(T*n), so if you have such solution – stick with it.(1) Converting the problem is
O(n)(2) This claim is true for this specific reduction alone, and NOT for the general case of polynomial reductions.