dp on trees help , csacademy .

Revision en3, by mokoto, 2019-02-21 13:42:47

in the problem sugarel and love , how to choose two sons such that we can maximize

DP[i][1]={max(DP[j][0]+v[i][j]+DP[t][0]+v[i][t])∣ where j and t are sons of i}. For all other sons, we add max(DP[j][0],DP[j][1],DP[j][2]) as given in editorial

since there can be nC2 choices time complexity would be O(n2) , how to do it in O(n) time .

i think we cant choose first two sums which gives max(DP[j][0]+v[i][j]+DP[t][0]+v[i][t]) as it will not always optimal .

any idea.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English mokoto 2019-02-21 13:42:47 1 Tiny change: 'ink we can choose fi' -> 'ink we cant choose fi'
en2 English mokoto 2019-02-21 13:42:21 86
en1 English mokoto 2019-02-21 13:41:51 770 Initial revision (published)