I think DP soln would be :
int leastPay(int[] demands, int sum, int index) {
if(index == demands.length)
return sum;
else {
if(sum < demands[index])
return leastPay(demands, sum+demands[index], index+1);
else
return Math.min(leastPay(demands, sum, index+1),
leastPay(demands, sum+demands[index], index+1));
}
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.