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 的资料.初步看了 ...
随机推荐
- chrome 31删除输入框的历史记录
chrome 31删除输入框的历史记录 TMD居然要用Shift + delete 了.... 为毛!!!
- bzoj1185
一遇到数学题和计算几何题我就要调半天…… 玛雅,我真是太弱了…… 基本思路很简单,先上凸包,然后矩形与凸包一边重合,然后旋转卡壳即可 然而我没怎么写过计算几何题,一开始写的各种囧,后来看了hzwer的 ...
- Parallel并行运算实例
并行运算Parallel,是.net 4.0版本里添加的新处理方式,主要充分利用CPU.任务并发的模式来达到提高运算能力.简单理解为每个CPU都在处理任务,而不会让它们空闲下来. 直接看实例: nam ...
- 玩转EasyUi弹出框
这两天在搞EasyUi的弹出框,弹出框之前也搞过很多个版本,总是觉得不那么完美,刚好最近有时间,就往多处想了想,功能基本上达到我的预期,并且在开发过程中遇到很多小技巧,特撰文如下. 走起:在EasyU ...
- fancybox 点击 js脚本判断验证,fancybox的宽度高度设置
当我们在使用fancybox做弹出窗口的时候,可能在弹窗之前就需要判断一些验证条件,例如我这里有个案例,用户必须先得勾选一个 那么怎么做呢?我们用到fancybox的一个onStart方法就可以了 $ ...
- 数学语言和程序语言的对比:面向过程与面向集合&命题
共同之处:都使用字符串或数值来引用一个客观实体.当然数字和字符串也可以作为实体对象,这取决于人的解释. 不同之处:数学语句每一行都给出了一个结论, 程序语句的每一行都定义了一个过程.注意这里所指的程序 ...
- validator的验证
通常喜欢这么写验证 <form method="post" data-ajax="false" action="/Shppping/PlaceO ...
- 最好用的汉字转拼音代码PinYin4Objc(PinYin4J的objc版本)
转:https://github.com/kimziv/PinYin4Objc 最好用的汉字转拼音代码PinYin4Objc(PinYin4J的objc版本)(更新到v1.1.1,增加block异步处 ...
- asp.net MVC 应用程序的生命周期(下)
看看上面的UrlRoutingModule源码里面是怎么实现Init方法的,Init()方法里面我标注红色的地方: application.PostResolveRequestCache += new ...
- Android 获取本机WIFI及3G网络IP
获取本机WIFIprivate String getLocalIpAddress() { WifiManager wifiManager = (WifiManager) getSystemServic ...