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.

Let A1,A2,,AN denote the sets of tasks with weights 1,2,,N, respectively. Additionally, let B2,B3,,BN denote the sets of tasks with weights 1 or 2, 2 or 3, …, N1 or N, respectively. Finally, let B1=0.

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 T, we need to check whether another task from the set BT has already been taken. Therefore, it is sufficient to have a table of the form dp[t][b].

This yields the following relations:

dp[0][0]=1dp[0][1]=0dp[i][0]=dp[i1][0]×(Ai+Bi)+dp[i1][1]×(Ai+Bi1)dp[i][1]=dp[i1][0]×Bi+dp[i1][1]×Bi+1


Comments


  • 0
    Anshv2  commented on Oct. 17, 2024, 12:17 a.m.

    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.