dp on trees help , csacademy .

Правка en3, от 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский mokoto 2019-02-21 13:42:47 1 Tiny change: 'ink we can choose fi' -> 'ink we cant choose fi'
en2 Английский mokoto 2019-02-21 13:42:21 86
en1 Английский mokoto 2019-02-21 13:41:51 770 Initial revision (published)