Greedy algorithm can't help in that case. And it couldn't be compared with both fractional or 0-1 knapsack problems. The first could be resolved by greedy algorithm in O(n) and the second is NP.
The problem you have could be brute-forced in O(2^n). But you could optimize it using dynamic programming.
1) Sort intervals by start time.
2) Initialize int[] costs = new int[jobs.length] with Integer.MIN_VALUE (or any negative value);
3) Define follow recursive routine (here is Java):
private int findCost(Job[] jobs, int k, int[] costs) {
if(k >= jobs.length) {
return 0;
}
if(costs[k] < 0) {
int x = findNextCompatibleJob(jobs, k);
int sumK = jobs[k].cost + findCost(jobs, x, costs);
int sumK1 = findCost(jobs, k + 1, costs);
costs[k] = Math.max(sumK, sumK1);
}
return costs[k];
}
private int findNextCompatibleJob(Job[] jobs, int k) {
int finish = jobs[k].finish;
for(int i = k + 1; i < jobs.length; i++) {
if(jobs[i].start > finish) {
return i;
}
}
return Integer.MAX_VALUE;
}
4) Start recursion with k = 0;
I have implemented only recursion routine while other parts are trivial. I considered that any cost is >= 0. If there could be negative cost jobs we need to add check for that and just pass that jobs without consideration.