trees + divide and conquer + dp