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. [置顶] C++为什么是C++而不是++C

    来自<C++ primer> 问:C++为什么是C++而不是++C 答 :C++之名是Rick Mascitti在1983年夏天定名,c说明它的本质实在C语言演化而来的,”++“是C语言的 ...

  2. Json for Java API学习

    首先声明:本文来个非常多网友的博客,我通过參考了他们的博客,大致的了解了一些项目中经常使用的Json in java 类和方法,以及关于json的个人理解 个人对json的一些简单理解 在近期的学习中 ...

  3. hdu 3309 Roll The Cube ( bfs )

    Roll The Cube Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. ByteBuffer和String的互相转换

    import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java ...

  5. DOS批处理延时技术

    DOS批处理延时技术 举个例子,我们要延时5秒打开gdh.txt这个文件,可以用以下几个方法 方法一:ping  缺点:时间精度为1秒,不够精确   www.2cto.com   @echo off  ...

  6. 基于CORS的geoserver同源访问策略

    这个问题理顺整个2天.终于攻克.记录下来. 1.下载文件 首先下载cors压缩包,解压,得到的是org/mortbay/servlets/CrossOriginFilter.class文件,把此文件拷 ...

  7. php 汉字转拼音 [包含20902个基本汉字+5059生僻字]

    原文:php 汉字转拼音 [包含20902个基本汉字+5059生僻字] 昨天在转换拼音的时候发现个bug,有好多字都无法转换,不过也不能怪他,毕竟人家的库才8k,应该只有常用的.无奈上网找了下,发现一 ...

  8. Java正則表達式演示样例

    import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches { public s ...

  9. 【PLSQL】绑定变量,活跃SQL,软硬解析解析

    ************************************************************************   ****原文:blog.csdn.net/clar ...

  10. linux下执行strlwr函数出错:ld returned 1 exit status

    执行strlwr函数时报错.源程序例如以下: #include<stdio.h> #include<string.h> void main() { char s[10]={&q ...