/* State: Accepted 1557 296MS 244K 858 B C++ ACb0y Author: ACb0y Date: 2010-7-27 Type: search (subset search) Description: hdu 1557 权利指数 */ #include <iostream> using namespace std; int sum; //保存原始数据 int data[21]; //保存结果的数组 int cnt[21]; //用来标记是否被访问过 int vis[21]; int main() { int i, j; int cas; #ifndef ONLINE_JUDGE freopen("1557.txt", "r", stdin); #endif cin >> cas; while (cas--) { int n; cin >> n; sum = 0; for (i = 0; i < n; i++) { cin >> data[i]; sum += data[i]; } //sum保存总票数的一半 sum /= 2; memset(cnt, 0, sizeof(vis)); //子集枚举1~(2^n - 1) int t = (1 << n) - 1; for (i = 1; i <= t; i++) { int tempSum = 0; int temp = i; j = 0; memset(vis, 0, sizeof(vis)); //遍历每个子集并累加票数 while (temp != 0) { if (temp & 1) { vis[j] = 1; tempSum += data[j]; } temp >>= 1; j++; } //如果子集的票数之和大于总票数的一半,且缺少第j个团体的票数时就少于等于 //总票数的一半则说明第j团体在这个联盟中是一个关键的加入者,所以cnt[j]++ //即团体j的权利指数加1 if (tempSum > sum) { for (j = 0; j < n; j++) { if (vis[j] && tempSum - data[j] <= sum) { cnt[j]++; } } } } for (j = 0; j < n - 1; j++) { cout << cnt[j] << " "; } cout << cnt[j] << endl; } return 0; }