HDU 5680 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 水题相关推荐
- HDU 6264 Super-palindrome(CCPC2017杭州) 水题
http://acm.hdu.edu.cn/showproblem.php?pid=6264 题目大意:给定字符串TTT,使得该字符串的每个长度为奇数的子串都是回文串,求至少要修改的字符的数量. 思路 ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 【HDU - 5585】Numbers (水题,数学,数论)
题干: There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise ...
- HDU 2549 壮志难酬 (水题,但有个小坑!)
壮志难酬 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...
- HDU 5112 A Curious Matt 水题
A Curious Matt Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- hdu 5062 Beautiful Palindrome Number(水题)
题目链接:hdu 5062 Beautiful Palindrome Number 题目大意:略. 解题思路:暴力或者手算都可以,注意手算的话,分别算出1,2,3...位的情况后,答案是累加上去的. ...
- hdu 4541 Ten Googol 小水题
Ten Googol Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total S ...
- HDU Senior's Gun (水题)
题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...
最新文章
- Day13 python基础---内置函数1
- linux用数字方式显示文件权限,全面解析Linux数字文件权限
- 边框画的三角形给shadow
- java中的数据加密1 消息摘要
- 小程序promise封装post请求_微信小程序 es6-promise.js封装请求与处理异步进程
- VMware Workstation 8.0安装VMTools时提示找不到GCC的解决办法
- 【windows】安装pytorch1.7.1-cpu版本的geometric过程记录
- java agent技术原理及简单实现
- go语言按行读取文件
- AutoCompleteExtender智能扩展实例
- 斗罗大陆真3D手游实力上线,带你感受魂兽猎杀的超燃时刻
- 巴铁 无人驾驶_巴铁?Clip-air?请查收汽车的最新玩法
- 软件测试基础课程学习笔记3---软件测试方法
- 开源公司内部的微信爬虫,寻求志同道合的人一起来改进
- tl-wn821n无线网卡驱动 linux,tlwn821n 300m无线网卡驱动 官方最新版
- Qt各版本官方下载地址
- ios 请在设置中打开相机权限_ios开发相机权限问题
- HBase的rowKey设计技巧
- 工业锅炉计算机控制系统框图,锅炉控制(汇总).ppt
- 华为21级程序员月薪27万,你怎么看?