Reputation: 239
Given n checks, each of arbitrary (integer) monetary value, decide if the checks can be partitioned into two parts that have the same monetary value.
I'm beyond mind blown on how to solve this. Is there an algorithm to solve this in polynomial time or is this NP-Complete?
Upvotes: 1
Views: 272
Reputation: 4888
Actually you can solve this in O(n*sum/2) using dynamic programming, first sum up all checks into a varaibel sum, then you can perform dp on the checks values (either take it or leave it or take it) and check at the end if that sum is equal to s/2.
Upvotes: 0
Reputation: 46960
Yes it's an NP complete problem. It's a variation of the subset sum problem.
Upvotes: 2