rama_pang's blog

By rama_pang, 20 months ago, In English

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
  • Vote: I like it
  • +45
  • Vote: I do not like it

»
20 months ago, # |
  Vote: I like it -8 Vote: I do not like it

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

  • »
    »
    20 months ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    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.