zxa and set

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=4681

Description

zxa has a set A={a1,a2,⋯,an}, which has n elements and obviously (2n−1) non-empty subsets.

For each subset B={b1,b2,⋯,bm}(1≤m≤n) of A, which has m elements, zxa defined its value as min(b1,b2,⋯,bm).

zxa is interested to know, assuming that Sodd 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 Seven 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 |Sodd−Seven|, can you help him?

Input

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 a1,a2,⋯,an.

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

1≤T≤100,1≤n≤30,1≤ai≤109

Output

For each test case, output in one line a non-negative integer, repersent the value of |Sodd−Seven|.

Sample Input

3
1
10
3
1 2 3
4
1 2 3 4

Sample Output

10
3
4

Hint

题意

zxa有一个集合\(A=\{a_1,a_2,\cdots,a_n\}\),\(n\)表示集合\(A\)的元素个数,这个集合明显有\((2^n-1)\)个非空子集合。

对于每个属于\(A\)的子集合\(B=\{b_1,b_2,\cdots,b_m\}(1\leq m\leq n)\),\(m\)表示集合\(B\)的元素个数,zxa定义它的价值是\(\min(b_1,b_2,\cdots,b_m)\)。

zxa很好奇,如果令\(S_{odd}\)表示集合\(A\)的所有含奇数个元素的非空子集合的价值之和,\(S_{even}\)表示集合\(A\)的所有含偶数个元素的非空子集合的价值之和,那么\(|S_{odd}-S_{even}|\)是多少,你能帮助他吗?

题解:

不管是数学方法,或者瞎爆搜,可以猜到答案就是最大值

直接输出就好了

代码

#include<bits/stdc++.h>
using namespace std;void solve()
{int n;scanf("%d",&n);int ans=0,x;for(int i=1;i<=n;i++){scanf("%d",&x);ans=max(ans,x);}printf("%d\n",ans);
}
int main()
{int t;scanf("%d",&t);while(t--)solve();return 0;
}

转载于:https://www.cnblogs.com/qscqesze/p/5495720.html

HDU 5680 zxa and set 水题相关推荐

  1. HDU 6264 Super-palindrome(CCPC2017杭州) 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=6264 题目大意:给定字符串TTT,使得该字符串的每个长度为奇数的子串都是回文串,求至少要修改的字符的数量. 思路 ...

  2. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  3. 【HDU - 5585】Numbers (水题,数学,数论)

    题干: There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise ...

  4. HDU 2549 壮志难酬 (水题,但有个小坑!)

    壮志难酬 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...

  6. HDU 5112 A Curious Matt 水题

    A Curious Matt Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  7. hdu 5062 Beautiful Palindrome Number(水题)

    题目链接:hdu 5062 Beautiful Palindrome Number 题目大意:略. 解题思路:暴力或者手算都可以,注意手算的话,分别算出1,2,3...位的情况后,答案是累加上去的. ...

  8. hdu 4541 Ten Googol 小水题

    Ten Googol Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total S ...

  9. HDU Senior's Gun (水题)

    题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...

最新文章

  1. Day13 python基础---内置函数1
  2. linux用数字方式显示文件权限,全面解析Linux数字文件权限
  3. 边框画的三角形给shadow
  4. java中的数据加密1 消息摘要
  5. 小程序promise封装post请求_微信小程序 es6-promise.js封装请求与处理异步进程
  6. VMware Workstation 8.0安装VMTools时提示找不到GCC的解决办法
  7. 【windows】安装pytorch1.7.1-cpu版本的geometric过程记录
  8. java agent技术原理及简单实现
  9. go语言按行读取文件
  10. AutoCompleteExtender智能扩展实例
  11. 斗罗大陆真3D手游实力上线,带你感受魂兽猎杀的超燃时刻
  12. 巴铁 无人驾驶_巴铁?Clip-air?请查收汽车的最新玩法
  13. 软件测试基础课程学习笔记3---软件测试方法
  14. 开源公司内部的微信爬虫,寻求志同道合的人一起来改进
  15. tl-wn821n无线网卡驱动 linux,tlwn821n 300m无线网卡驱动 官方最新版
  16. Qt各版本官方下载地址
  17. ios 请在设置中打开相机权限_ios开发相机权限问题
  18. HBase的rowKey设计技巧
  19. 工业锅炉计算机控制系统框图,锅炉控制(汇总).ppt
  20. 华为21级程序员月薪27万,你怎么看?

热门文章

  1. 早上起床后喝一杯白开水是非常有好处的
  2. 过年最大的烦恼是什么?
  3. 莺颠燕狂的拼音及解释
  4. 家境普通的年轻人出路到底在何方?
  5. 做网店大家千万要注意
  6. 如何实现一根网线连接路由器,即能上网又可以使用ITV?
  7. java项目.gitignore文件过滤规则
  8. 思科模拟器划分子网实验报告_模拟多子网群集以设置SQL Server Always On可用性组–实验设置
  9. 了解SQL Server CASE语句
  10. Selenium(Python)页面对象+数据驱动测试框架