HDU 1557 权利指数 状态压缩 暴力

ACM

题目地址:HDU 1557 权利指数

题意: 

中文题,不解释。

分析: 

枚举全部集合,计算集合中的和,推断集合里面的团体是否为关键团队。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* File: 1557.cpp
* Create Date: 2014-06-28 14:47:58
* Descripton: brute force/ set
*/ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 20;
int t, n, tot;
int a[N], ans[N], sub[N], scnt; int main() {
scanf("%d", &t);
while (t--) {
memset(ans, 0, sizeof(ans));
tot = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
tot += a[i];
} tot /= 2; // half total tickets
int ALL = (1 << n); // subset 1 ~ 2^n-1
for (int i = 0; i < ALL; i++) {
scnt = 0; // this subset's number
int tmp = i, sum = 0, no = 0;
while (tmp) {
if (tmp & 1) { // if no is in subset
sub[scnt++] = no;
sum += a[no];
}
tmp >>= 1;
no++;
} if (sum > tot) { // if success
for (int j = 0; j < scnt; j++) {
if (sum - a[sub[j]] <= tot) { // find out
ans[sub[j]]++;
}
}
}
} // output
printf("%d", ans[0]);
for (int i = 1; i < n; i++) {
printf(" %d", ans[i]);
}
puts("");
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU 1557 权利指数 国家压缩 暴力的更多相关文章

  1. hdu - 5045 - Contest(国家压缩dp)

    意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...

  2. HDU 1885 Key Task 国家压缩+搜索

    点击打开链接 Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

  5. HDU 3131 One…Two…Five! (暴力搜索)

    题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...

  6. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  7. HDU 4858 项目管理(邻接表 暴力模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...

  8. HDU 4511 (AC自动机+状态压缩DP)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...

  9. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

随机推荐

  1. What is tradebit?

    The Tradebit Fact Sheet What is tradebit?

  2. Xcode 4.6.2 运行次数为偶数程序崩溃问题

    如果你的MAC 系统升级到10.8.4  Xcode升级到4.6.2,在工程运行第二次.第四次.第六次 ... 的时候程序就会崩溃 无论是新建的模板工程也会这样,这个属于系统BUG,在stackove ...

  3. 不可不知的DIP、IoC、DI以及IoC容器

    面向对象设计(OOD)有助于我们开发出高性能.易扩展以及易复用的程序.当中.OOD有一个重要的思想那就是依赖倒置原则(DIP),并由此引申出IoC.DI以及Ioc容器等概念. 本文首先用实例阐述四个概 ...

  4. Struts2 拦截器具体配置过程

    拦截器差点儿遍布每个程序中,所以贴出拦截器配置的具体过程,希望可以帮到大家. Struts2 拦截器具体配置过程 <interceptors> <!-- 先定义拦截器 --> ...

  5. Ubuntu 32下Android NDK+NEON的配置过程及简单使用举例

    1.  利用VMware在Windows7 64位下安装Ubuntu13.10 32位虚拟机: 2.  从 https://developer.android.com/tools/sdk/ndk/in ...

  6. java中常用的字符串的截取方法

    java中常用的字符串的截取方法   1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int l ...

  7. poj1947(树形dp)

    题目链接:http://poj.org/problem?id=1947 题意:给n(n<=150)个点的一棵树,求删掉最少边数k使得最后该树只剩下p(1<=p<=n)个节点.(求最小 ...

  8. 强势围观,CSDN代码引用bug

    看我写的一篇blog  http://blog.csdn.net/laijieyao/article/details/41014355,在代码上引用了微软雅黑的字体,结果代码显示出来把我给惊呆了 竟然 ...

  9. 如何通过shell脚本操作MongoDB

    通过shell脚本对MongoDB进行自动化操作 运行写好的 ./show.sh 脚本 发现能够建立mongo链接 #!/bin/sh mongo WordPress --eval "sho ...

  10. 在VS2012中使用GitHub

    注册GitHub账号(DeanZhouLin) https://github.com/ 向GitHub中添加一个仓库(Test) *创建完成后,记录该仓库的地址:https://github.com/ ...