Trees | DP

So i came across this interesting problem, i wonder how to approach this if the leaf values were in postorder or preorder ?