当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5680:zxa and set

题目描述
zxa has a set $A=\{a_1,a_2,\cdots,a_n\}$, which has $n$ elements and obviously $(2^n-1)$ non-empty subsets.

For each subset $B=\{b_1,b_2,\cdots,b_m\}(1\leq m\leq n)$ of $A$, which has $m$ elements, zxa defined its value as $\min(b_1,b_2,\cdots,b_m)$.

zxa is interested to know, assuming that $S_{odd}$ represents the sum of the values of the non-empty sets, in which each set $B$ is a subset of $A$ and the number of elements in $B$ is odd, and $S_{even}$ represents the sum of the values of the non-empty sets, in which each set $B$ is a subset of $A$ and the number of elements in $B$ is even, then what is the value of $|S_{odd}-S_{even}|$, can you help him?
输入解释
The first line contains an positive integer $T$, represents there are $T$ test cases.

For each test case:

The first line contains an positive integer $n$, represents the number of the set $A$ is $n$.

The second line contains $n$ distinct positive integers, repersent the elements $a_1,a_2,\cdots,a_n$.

There is a blank between each integer with no other extra space in one line.

$1\leq T\leq 100,1\leq n\leq 30,1\leq a_i\leq 10^9$
输出解释
For each test case, output in one line a non-negative integer, repersent the value of $|S_{odd}-S_{even}|$.
输入样例
3
1
10
3
1 2 3
4
1 2 3 4
输出样例
10
3
4

提示
For the first sample, $A=\{10\}$, which contains one subset $\{10\}$ in which the number of elements is odd, and no subset in which the number of elements is even, therefore $S_{odd}=10,S_{even}=0,|S_{odd}-S_{even}|=10$.

For the second sample, $A=\{1,2,3\}$, which contains four subsets $\{1\},\{2\},\{3\},\{1,2,3\}$ in which the number of elements is odd, and three subsets $\{1,2\},\{2,3\},\{1,3\}$ in which the number of elements is even, therefore $S_{odd}=1+2+3+1=7,S_{even}=1+2+1=4,|S_{odd}-S_{even}|=3$.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #83

源链接: HDU-5680

最后修改于 2020-10-25T23:24:45+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)