CF526B.Om Nom and Dark Park
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.

The park consists of 2_n_ + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depth n. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2_n_, 2_n_ + 1, ..., 2_n_ + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each square i (2 ≤ i < 2_n_ + 1) there is a road to the square
. Thus, it is possible to go from the park entrance to each of the exits by walking along exactly n roads.

To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square
has a__i lights.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
奥姆·诺姆(Om Nom)是游戏《割绳子》(Cut the Rope)的主角。他是一只聪明可爱的小怪物,喜欢去公园另一侧拜访朋友们。然而,幽暗陈旧的公园连无所畏惧的奥姆·诺姆都会感到害怕,因此他请求你帮助他。

该公园由 2n+1−1 个方格通过道路连接而成,其结构恰好构成一棵深度为 n 的满二叉树。更准确地说:公园入口位于编号为 1 的方格;公园出口位于编号为 2n,2n+1,…,2n+1−1 的方格,这些出口分别通向奥姆·诺姆各位朋友的家;对每个方格 i(其中 2≤i<2n+1),都有一条道路通向方格 ⌊2i⌋。因此,从公园入口出发,沿道路恰好经过 n 条边即可到达任一出口。

为在夜晚照亮路径,公园管理员在每条道路上安装了路灯。从方格 i 通往方格 ⌊2i⌋ 的这条道路装有 ai 盏灯。
奥姆·诺姆喜欢在前往朋友家的路上数路灯的数量。但公园里栖息着蜘蛛,令他心生恐惧,因此他不愿走那些照明不足的道路。他希望:从入口到任意一个朋友家(即任一出口)的整条路径上,所经道路的路灯总数完全相同——这会让他感到安心。
他请你帮忙安装额外的路灯。请确定:为使从入口到任意一个公园出口的路径所含路灯总数均相等,至少需要额外安装多少盏路灯?你可以在任意一条道路上添加任意数量的路灯。
输入格式
The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.
The next line contains 2_n_ + 1 - 2 numbers _a_2, _a_3, ... a_2_n + 1 - 1 — the initial numbers of street lights on each road of the park. Here a__i is the number of street lights on the road between squares i and
. All numbers a__i are positive integers, not exceeding 100.
第一行包含一个整数 $ n ( 1 \leq n \leq 10 $)——表示从入口到任意出口路径上的道路数量。
下一行包含 $ 2n+1-2 $ 个数字 $ a_2,,a_3,,\dots,,a_{2n+1-1} $ —— 表示公园中每条道路上初始的路灯数量。其中 $ a_i $ 表示连接方格 $ i $ 与
的道路上的路灯数量。所有 $ a_i $ 均为正整数,且不超过 100。
输出格式
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
输出为使奥姆·诺姆感到安全,我们需要在公园道路上增设的最少路灯数量。
输入输出样例
输入#1
2 1 2 3 4 5 6
输出#1
5
说明/提示
Picture for the sample test. Green color denotes the additional street lights.

样例测试的示意图。绿色表示新增的路灯。

输入解题思路,AI测评打分。不知道怎么写?