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. 做外贸,独立B2C商城好,还是平台好

    随着跨境电商热的来临,越来越多的国内企业选择进军跨国电商,那么企业要想进军以互联网跨国销售,通常会通过两种途径,一种是建立独立运营的B2C商城,还有一种是依托alibaba,dhgate,aliexp ...

  2. poj 2513 连接火柴 字典树+欧拉通路 好题

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27134   Accepted: 7186 ...

  3. Android中九种dialog对话框代码

    public class MainActivity extends Activity { private static final int MAX_PROGRESS = 100; private st ...

  4. 1-5html文件基本结构

    认识html文件基本结构 1)这一节中我们来学习html文件的结构:一个HTML文件是有自己固定的结构的. <html> <head>...</head> < ...

  5. B. 沙漠之旅(分组背包)

    B. 沙漠之旅 Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: % ...

  6. SSDTHook实例--编写稳定的Hook过滤函数

    解说怎样写Hook过滤函数,比方NewZwOpenProcess.打开进程. 非常多游戏保护都会对这个函数进行Hook. 因为我们没有游戏保护的代码,无法得知游戏公司是怎样编写这个过滤函数. 我看到非 ...

  7. filezilla安装

    [alexus@wcmisdlin02 bin]$ ./filezilla ./filezilla: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not ...

  8. JavaScript中的对象(一)

    Email:longsu2010 at yeah dot net 最近我和朋友谈起JavaScript中对象的问题.朋友以写JavaScript为生,而且生活的很好,然而我发现他并不真正懂这们语言的某 ...

  9. HDU 4454 - Stealing a Cake(三分)

    我比较快速的想到了三分,但是我是从0到2*pi区间进行三分,并且漏了一种点到边距离的情况,一直WA了好几次 后来画了下图才发现,0到2*pi区间内是有两个极值的,每个半圆存在一个极值 以下是代码 #i ...

  10. Android圆弧形ListView的实现

    本文带大家来实现ListView的圆弧形的分布排列,原理非常easy,就是依据ListView的每个Item的高度来对每个item进行偏移. 首先自己定义一个LinearLayout,这是ListVi ...