HDU 5680 zxa and set (数学 推导结论)

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;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5697220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值