ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1018. Двоичная яблоня

Recursion
Послано marat 19 апр 2011 16:58
Let C[i][j] be weight of the edge( i, j). A( n, k ) - maximal amount of apples under k-th node after n cuts. B(k) - amount of edges under k-th node. Then ( k+ - right child and k-  - left child of the k-th nod )

A(n,k) = max{ a(n - B(k-), k+ ), if ( n > B(k-))                              }
            { a(n - B(k+), k- ), if ( n > B(k+))                              }                                                                           .           { MAX i FROM( 0) TO (n) OF a(n-i,k+)+a(i,k-) + C[k][k-]+C[k][k+]  }
            { A(0,k+) + A(0, k- ) + C[k][k-]+C[k][k+], if n = 0               }
            { - MAXAMOUNTOFAPPLES, if (k+ or k- doesn't exist AND n>0)        }

1-th and 2-th lines: one can cut left or rigth edge, if so we have to cut n-B(k+-) edges in the other subtree.

3-th line:           one can save both left and right edges, if so we have to cut i edges in left and n-i edges in the rigth subtrees. Choose maximal value changing i variable.

4-th line:           in this case we should count amout of apples under k-th node. It's equal to amount of apples in subtrees plus edge weights.

5-th line:           k is a leaf. if n>0 there is nothing to cut => deny this situation by MAXAMOUNTOFAPPLES with negative sign. I used MAXAMOUNTOFAPPLES  = 3000000

After that -  DP.
Re: Recursion
Послано Denis Astanin (KPI) 3 май 2011 22:45
Can you write it on russian?