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

Автор rama_pang, 19 месяцев назад, По-английски

The contest announcement and invitation link is here. The contest link is here.

A. Artistic Masterpiece

Tutorial

B. Broken Calculator

Tutorial

C. Counting Trees

Tutorial

D. Decision Making

Tutorial

E. Erosion Filter

Tutorial

F. Fizz Buzz

Tutorial

G. Geometry is Fun

Tutorial

H. Hashing Algorithm

Tutorial

I. Interconnectivity Measure

Tutorial

J. Judo Championship

Tutorial

K. Knapsack 101

Tutorial

L. Language Interpreter

Tutorial

M. Most Difficult

Tutorial

N. Never Give Up

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

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

Mind Blowing Contest, Really Love B and C, But a bit confused in C, Can anyone explain thoroughly, please

  • »
    »
    19 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

    If you read the problem statement and draw graphs for the trees, you will find that the tree is structured like trees with k branches.


    0 | \ 1 2 |\ |\ 3 4 5 6

    Consider DP, let $$$f(i,j)$$$ be the answer for first $$$i$$$ nodes (without counting the root) splitting for $$$j$$$ trees, then consider the last node: either we cut the edge from the $$$i$$$-th node to its parent in order to split a tree from it, or we don't cut the edge and move to the previous node. This idea is a bit like a knapsack problem.

    This gives us a formula.

    $$$ f(i,j) = f(i-1,j-1) + f(i-1,j) $$$

    Therefore, the formula is exactly the recurrence of combinatoric numbers.

    Initially, there is a tree, so we have to cut $$$c-1$$$ edges. The root is not counted, because it doesn't have a parent edge. So the total number of nodes is $$$n-1$$$. Therefor the answer is $$$f(n-1,c-1)$$$, which is $$$n-1$$$ chooses $$$c-1$$$. Finally, we multiply this number by $$$2$$$ for reversing all colors.