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;
}
HDU 5680 zxa and set (数学 推导结论)的更多相关文章
- HDU 5858 Hard problem (数学推导)
Hard problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5858 Description cjj is fun with ...
- hdu 5584 LCM Walk(数学推导公式,规律)
Problem Description A frog has just learned some number theory, and can't wait to show his ability t ...
- HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total S ...
- HDU-1719 Friend 数学推导
Friend HDU - 1719 Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend n ...
- 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5
上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...
- 关于不同进制数之间转换的数学推导【Written By KillerLegend】
关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- 『sumdiv 数学推导 分治』
sumdiv(POJ 1845) Description 给定两个自然数A和B,S为A^B的所有正整数约数和,编程输出S mod 9901的结果. Input Format 只有一行,两个用空格隔开的 ...
- LDA-线性判别分析(二)Two-classes 情形的数学推导
本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...
随机推荐
- AndroidApplication Fundamentals(Android应用基础)
AndroidApplication Fundamentals(Android应用基础) Android应用采用Java编程语言来编写,AndroidSDK工具编译我们的代码,连同任何数据和资源文件一 ...
- Codeforces Beta Round #2B(dp+数学)
贡献了一列WA.. 数学很神奇啊 这个题的关键是怎么才能算尾0的个数 只能相乘 可以想一下所有一位数相乘 除0之外,只有2和5相乘才能得到0 当然那些本身带0的多位数 里面肯定含有多少尾0 就含有多少 ...
- iOS开发:Swift多线程GCD的使用
除了上一篇文章说到到NSThread线程,还有一个GCD(Grand Central Dispath),是Apple新开发的一个解决多核编程的解决方案,充分的利用CPU资源,将所有的任务,放到一个任务 ...
- iOS开发:在Xcode中用Pods管理第三方库
之前写了一篇 iOS开发:在Swift中调用oc库 ,今天记录一下如何用Pods的方式来管理第三方库,包括Swift/Object-C的库. 在这之前请先查阅Guides.CocoaPods如何使用的 ...
- UVa 11054 Wine trading in Gergovia【贪心】
题意:给出n个等距离的村庄,每个村庄要么买酒,要么卖酒,买酒和卖酒的总量相等, 把k个单位的酒从一个村庄运送到相邻的村庄,需要耗费k个单位劳动力,问怎样运送酒使得耗费的劳动力最少 买 卖 ...
- HNOI2002营业额统计(平衡树)
标准的平衡树. 贴个splay吧 var v,l,r,fa:..] of longint; root,x,i,n,ans:longint; procedure zig(x:longint); var ...
- 图形数据库、NOSQL和Neo4j
简介 在众多不同的数据模型里,关系数据模型自80年代就处于统治地位,而且有不少实现,如Oracle.MySQL和MSSQL,它们也被称为关系数据库管理系统(RDBMS).然而,最近随着关系数据库使用案 ...
- 自定义View,圆形头像
1. 效果图 2. xml中 <com.etoury.etoury.ui.view.CircleImg android:id="@+id/user_info_head_img" ...
- Java 知识点:序列化
首先明确一点:默认的序列化方法速度很慢,因为需要对整个对象和他的类都进行保存,因此我们建议自定义序列化格式. ObjectInputStream和ObjectOutputStream 用途 Objec ...
- jQuery的威力
jQuery如此之好用,和其在获取对象时使用与CSS选择器兼容的语法有很大关系,毕竟CSS选择器大家都很熟悉(关于CSS选择器可以看看十分钟搞定CSS选择器),但其强大在兼容了CSS3的选择器,甚至多 ...