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

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

Hi, Codeforces. I've recently found an interesting problem:

Given an undirected tree with n vertices. Find out how many different ways you can orient the edges of the tree so that the result graph will contain exactly m vertices with zero outdegree modulo 109 + 7,   (1 ≤ n ≤ 1000, 0 ≤ m ≤ n).

Could someone help me with this problem and explain the solution?

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

»
7 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

dp[v][cnt][flag] is the number of ways to make cnt vertices with zero outdegree in the subtree of v, and flag is 1 if the vertex v have a zero outdegree else it is 0 (so n * m * 2 memory)

to recalc this dp you just go with dfs and then you do knapsack-like solution like in this task 815C