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 denote the sets of tasks with weights , respectively. Additionally, let denote the sets of tasks with weights or , or , …, or , respectively. Finally, 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 , we need to check whether another task from the set has already been taken. Therefore, it is sufficient to have a table of the form .
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.