Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя geniucos

Автор geniucos, история, 11 лет назад, По-английски

I've been thinking for about 2 months at a problem and I haven't manage to find a solution, so I've decided to ask for your help. The problem is pretty nice. It asks for the number of trees(2 trees are considered different if they are not isomorphs) with N vertices and diameter D. Here you have the link . It was given in Polish Algorithmic Engagements 2008 at the final round and as far as I know there are no written solutions for this kind of contest.

  • Проголосовать: нравится
  • +34
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +41 Проголосовать: не нравится

I have recently solved this problem, here is my code: http://ideone.com/ENhisf

Main idea is to observe that every tree has uniquely determined midpoint of all of its diameters, root our tree there (there are basically two cases — odd and even D) and use some dp to count everything. I used 3D dp array dp[n][d][s] which denotes "what is the number of rooted trees with n vertices, depth not larger than d and so that no son's subtree is larger than s" (I believe that last dimension can be omitted (but without changing the complexity)).