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. ios中addtarget的用法

    1.addtarget 的.部分使用事件没有直接的操作方式,需要进行调用.就要用addTarget. - (void)setupCustomView { self.customView = [[CHV ...

  2. android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法

    这篇文章介绍了android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法,有需要的朋友可以参考一下 布局文件中的TextView属性 复制代码代码如下: < ...

  3. UVA 10917 Walk Through the Forest(dijkstra+DAG上的dp)

    用新模板阿姨了一天,换成原来的一遍就ac了= = 题意很重要..最关键的一句话是说:若走A->B这条边,必然是d[B]<d[A],d[]数组保存的是各点到终点的最短路. 所以先做dij,由 ...

  4. UVA 10972 RevolC FaeLoN(边连通分量)

    坑了我一天的题目..跑了20ms挂了,就知道有个小毛病= = 无向图转有向图判强连通. 首先要知道什么样的无向图可以转化为强连通图?连通分量(环)自然是可以的:那么扩大范围(存在割顶),发现点连通分量 ...

  5. BZOJ 1610 连线游戏

    BZOJ不允许除以0. #include<iostream> #include<cstdio> #include<cstring> #include<cstd ...

  6. angular js 实例参数学习

    <!DOCTYPE html> <html> <head> <meta name="description" content=" ...

  7. 【RMQ问题】求数组区间最大值,NYOJ-1185-最大最小值

    转自:http://blog.csdn.net/lilongherolilong/article/details/6624390 先挖好坑,明天该去郑轻找虐 RMQ(Range Minimum/Max ...

  8. RAC集群时间同步服务

    集群时间同步服务在集群中的两个 Oracle RAC 节点上执行以下集群时间同步服务配置.Oracle Clusterware 11g 第 2 版及更高版本要求在部署了 Oracle RAC 的集群的 ...

  9. WAPI

    中国制定的WLAN安全标准WAPI 针对WLAN安全问题,中国制定了自己的WLAN安全标准:WAPI. 与其他无线局域网安全机制(如802.11i)相比,WAPI主要的差别体现在以下几个方面: • 双 ...

  10. link 参数

    -all-static do not do any dynamic linking at all -avoid-version do not add a version suffix if possi ...