Quote:
Can anybody code this problem in java
Most probably everyone here.
Quote:
I am new to Dynamic Programming and stuck somewhere, and could not figure out how to proceed further
As far as I can see, this requirement is not related to dynamic programming, but since you didn't post the complete text, I may be wrong.
To get help here, show your code and explain where you are stuck. By the way, complete the text of requirement.