Editorial for COCI '10 Contest 5 #4 Honi
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Let
The problem can now be solved using a dynamic programming approach; starting from the first weight (the least one) we choose a task for each weight. When choosing a task with the weight equal to
This yields the following relations:
Comments
For dp[i][1] the Bi term should be Bi+1 for the first term: dp[i][1] = dp[i-1][0] Bi+1 + dp[i-1][1] Bi+1.