102365: [AtCoder]ABC236 F - Spices

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

The shop supaisu-ya sells $2^N-1$ kinds of spices: Spice $1$, Spice $2$, $\ldots$, Spice $2^N-1$. One pack of each spice is in stock. For each $i = 1, 2, \ldots, 2^N-1$, Spice $i$ costs $c_i$ yen. Takahashi can buy any of these spices.

He plans to make curry after getting home by choosing one or more of the bought spices and mixing them.
If $k$ spices, Spice $A_1$, Spice $A_2$, $\ldots$, Spice $A_k$, are mixed, the hotness of the resulting curry is $A_1 \oplus A_2 \oplus \cdots \oplus A_k$, where $\oplus$ denotes the bitwise XOR.

Takahashi wants to decide the hotness of the curry based on his feeling after getting home. For now, he will buy a set of spices that allows him to make curry of any hotness from $1$ through $2^N-1$. Print the minimum possible amount of money Takahashi pays.

Constraints

  • $2 \leq N \leq 16$
  • $1 \leq c_i \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$c_1$ $c_2$ $\ldots$ $c_{2^N-1}$

Output

Print the minimum possible amount of money Takahashi pays.


Sample Input 1

2
4 5 3

Sample Output 1

7

If Takahashi buys Spice $1$ and $3$, he can make curry of any hotness from $1$ through $3$, as follows.

  • To make curry of hotness $1$, use just Spice $1$.
  • To make curry of hotness $2$, mix Spice $1$ and Spice $3$.
  • To make curry of hotness $3$, use just Spice $3$.

Here, Takahashi pays $c_1 + c_3 = 4 + 3 = 7$ yen, which is the minimum possible amount he pays.


Sample Input 2

4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

Sample Output 2

15

Input

题意翻译

有 $2 ^ N - 1$ 个数字,分别编号为 $1, 2, \dots, 2 ^ N - 1$,想获得编号为 $i$ 的数字需要支付 $c_i$ 的代价。 现在你可以从这些数字中选出一些数,使得你可以通过你选择的某些数的编号的异或和来表示出 $[1, 2 ^ N - 1]$ 中的所有数。 请你求出最少需要支付多少代价。

Output

分数:$500$分

问题描述

杂货店supaisu-ya出售$2^N-1$种香料:香料$1$、香料$2$、$\ldots$、香料$2^N-1$。每种香料都有一个包装在库存中。 对于每个$i = 1, 2, \ldots, 2^N-1$,香料$i$的价格为$c_i$日元。 Takahashi可以购买这些香料中的任意一种。

他计划在回家后选择购买的一种或多种香料进行混合来制作咖喱。 如果混合了$k$种香料,香料$A_1$、香料$A_2$、$\ldots$、香料$A_k$,那么混合后的咖喱的辣度为$A_1 \oplus A_2 \oplus \cdots \oplus A_k$,其中$\oplus$表示按位异或。

Takahashi想在回家后根据自己的感觉来决定咖喱的辣度。目前,他将购买一组香料,使他能够制作辣度从$1$到$2^N-1$的咖喱。输出Takahashi支付的最少金额。

限制条件

  • $2 \leq N \leq 16$
  • $1 \leq c_i \leq 10^9$
  • 输入中的所有值都是整数。

输入

输入以标准输入的形式给出:

$N$
$c_1$ $c_2$ $\ldots$ $c_{2^N-1}$

输出

输出Takahashi支付的最少金额。


样例输入1

2
4 5 3

样例输出1

7

如果Takahashi购买香料$1$和$3$,他可以制作辣度从$1$到$3$的咖喱,如下所示。

  • 要制作辣度为$1$的咖喱,只使用香料$1$。
  • 要制作辣度为$2$的咖喱,将香料$1$和香料$3$混合。
  • 要制作辣度为$3$的咖喱,只使用香料$3$。

在这里,Takahashi支付了$c_1 + c_3 = 4 + 3 = 7$日元,这是他支付的最少金额。


样例输入2

4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

样例输出2

15

加入题单

算法标签: