on-internet
← Community

Why does DP with optimal substructure sometimes not reduce to greedy, even when a choice looks obviously best?

Stack Overflow ·

In CLRS, Activity Selection uses a simple greedy rule (pick the earliest finishing activity) and it always gives the optimal answer. No DP needed. I tried the same idea on Weighted Job Scheduling (each job has start, end, profit, pick non-overlapping jobs for max profit). Picking the earliest finishing job first does not give the correct answer here. You need the full DP, i refers ith job: dp[i] = max(dp[i-1], profit[i] + dp[lastNonOverlapping(i)]) Both problems look almost the same. One needs greedy, other one needs DP. Is there a way to tell, just from the problem statement, whether greedy w

Comments

Sign in or sign up to comment and upvote.

No comments yet.