zxa and set

题目链接:

http://acm.hust.edu.cn/vjudge/contest/121332#problem/G

Description

zxa has a set , which has elements and obviously non-empty subsets.

For each subset of , which has elements, zxa defined its value as .

zxa is interested to know, assuming that represents the sum of the values of the non-empty sets, in which each set is a subset of and the number of elements in is odd, and represents the sum of the values of the non-empty sets, in which each set is a subset of and the number of elements in is even, then what is the value of , can you help him?

Input

The first line contains an positive integer , represents there are test cases.

For each test case:

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

The second line contains distinct positive integers, repersent the elements .

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

Output

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

Sample Input

3

1

10

3

1 2 3

4

1 2 3 4

Sample Output

10

3

4

Hint

题意:

给出集合A,B是A的任意子集;某个集合的权值定义为集合元素的最小值;

S-odd为元素个数为奇数的B的个数;

S-even为元素个数为偶数的B的个数;

求abs(S-odd - S-even);

题解:

看上去好像很麻烦,要算很多次;

尝试把每个元素在结果中出现的次数写成组合数的形式;

再按题意加起来,运用组合数相关公式可以很容易得到:

结果即为A中的最大值;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mid(a,b) ((a+b)>>1)
#define LL long long
#define maxn 600000
#define IN freopen("in.txt","r",stdin);
using namespace std; int n; int main(int argc, char const *argv[])
{
//IN; int t;cin>>t;
while(t--)
{
scanf("%d",&n);
int ans = -1;
while(n--){
int x;
cin >> x;
ans = max(ans, x);
} printf("%d\n", ans);
} return 0;
}

HDU 5680 zxa and set (数学 推导结论)的更多相关文章

  1. HDU 5858 Hard problem (数学推导)

    Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...

  2. hdu 5584 LCM Walk(数学推导公式,规律)

    Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...

  3. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

  4. HDU-1719 Friend 数学推导

    Friend HDU - 1719 Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend n ...

  5. 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5

    上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...

  6. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

  7. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  8. 『sumdiv 数学推导 分治』

    sumdiv(POJ 1845) Description 给定两个自然数A和B,S为A^B的所有正整数约数和,编程输出S mod 9901的结果. Input Format 只有一行,两个用空格隔开的 ...

  9. LDA-线性判别分析(二)Two-classes 情形的数学推导

    本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...

随机推荐

  1. apk反编译(5)用apktool重新生成一个未签名的apk

    用apktool反编译apk后,得到一个目录,里面有smali文件,可以对其修改,然后用apktool重新生成一个未签名的apk. 如,把smali文件中的广告部分去掉或改成自己的. 命令如下:与破解 ...

  2. html5 touch事件实现触屏页面上下滑动(一)

    最近做的做那个app的项目由于用overflow:hidden导致了很多问题,于是决定研究下html5的touch事件.想找个全面点的帖子真是难死了,虽然好多关于html5 touch的文章但大多都是 ...

  3. 【HDOJ】4080 Stammering Aliens

    1. 题目描述给定一个长为$n \in [1, 4000]$的字符串,求其中长度最长的子串,并且该子串在原串中出现至少$m$次,并求最右起始位置. 2. 基本思路两种方法:二分+后缀数组,或者二分+哈 ...

  4. JAVA中获取项目文件路径

    在java中获得文件的路径在我们做上传文件操作时是不可避免的. web 上运行 1:this.getClass().getClassLoader().getResource("/" ...

  5. 函数fsp_alloc_from_free_frag

    /**********************************************************************//** Allocates a single free ...

  6. org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked dir异常解决方法

    myeclipse用svn提交的时候报错: Attempted to lock an already-locked dir svn: Working copy 'D:/Program Files/My ...

  7. BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...

  8. vc2005编译ffmpeg以及ffplay

    ffmpeg编译过程:1 http://ffmpeg.zeranoe.com/builds/下载官方提供的源码,win32库和dll.2 新建vc2005 console空工程,把ffmpeg.h,f ...

  9. K2 学习笔记

    转:http://www.cnblogs.com/kaixuanpisces/category/149223.html k2 简介 工作流介绍 k2流程设计简介 K2流程设计详细版(图文)一 K2流程 ...

  10. MySQL row模式binlog复制原理

    http://www.360doc.com/content/14/1107/14/12904276_423333021.shtml