Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】
E. Mother of Dragons
There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more than one wall, no wall connects a castle to itself.
Sir Jaime Lannister has discovered that Daenerys Targaryen is going to attack his kingdom soon. Therefore he wants to defend his kingdom. He has k liters of a strange liquid. He wants to distribute that liquid among the castles, so each castle may contain some liquid (possibly zero or non-integer number of liters). After that the stability of a wall is defined as follows: if the wall connects two castles a and b, and they contain x and y liters of that liquid, respectively, then the strength of that wall is x·y.
Your task is to print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve.
The first line of the input contains two integers n and k (1 ≤ n ≤ 40, 1 ≤ k ≤ 1000).
Then n lines follows. The i-th of these lines contains n integers ai, 1, ai, 2, ..., ai, n (). If castles i and j are connected by a wall, then ai, j = 1. Otherwise it is equal to 0.
It is guaranteed that ai, j = aj, i and ai, i = 0 for all 1 ≤ i, j ≤ n.
Print the maximum possible sum of stabilities of the walls that Sir Jaime Lannister can achieve.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
3 1
0 1 0
1 0 0
0 0 0
0.250000000000
4 4
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
4.000000000000
In the first sample, we can assign 0.5, 0.5, 0 liters of liquid to castles 1, 2, 3, respectively, to get the maximum sum (0.25).
In the second sample, we can assign 1.0, 1.0, 1.0, 1.0 liters of liquid to castles 1, 2, 3, 4, respectively, to get the maximum sum (4.0)
题目链接:http://codeforces.com/contest/839/problem/E
分析__builtin_popcount()的使用及原理参看这里
下面给出AC代码:
#include "bits/stdc++.h"
using namespace std;
const int N = ;
const double eps = 1e-;
int n , k;
long long graph[N];
double ans;
int clique;
int bitcnt[ << ];
void solve(long long mask , int cur){
clique = max(clique , cur);
int idx = -;
int mx = ;
for(int i = ; i <= n ; ++i){
if(!((mask >> i) & )){
continue;
}
int tmp = __builtin_popcountll(graph[i] & mask);
if(idx == - || tmp > mx){
mx = tmp;
idx = i;
}
}
if(idx == -){
return;
}
clique = max(clique , cur + );
if(mx + + cur <= clique){
return;
}
solve((mask ^ (1LL << idx)) & graph[idx] , cur + );
solve(mask ^ (1LL << idx) , cur);
}
int main(){
scanf("%d %d" , &n , &k);
for(int i = ; i <= n ; ++i){
int tmp;
graph[i] = ;
for(int j = ; j <= n ; ++j){
scanf("%d" , &tmp);
graph[i] |= (1LL << j) * tmp;
}
}
long long mask = ;
for(int i = ; i <= n ; ++i){
mask |= 1LL << i;
}
clique = ;
solve(mask , );
ans = (1.0 * k * k) / (1.0 * clique * clique);
ans *= clique * (clique - );
ans /= ;
printf("%.6lf\n" , ans);
}
Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】的更多相关文章
- Codeforces 839E Mother of Dragons(极大团)
[题目链接] http://codeforces.com/contest/839/problem/E [题目大意] 现在有一些点,现在你有k的液体,随意分配给这些点, 当两个点有边相连的时候,他们能产 ...
- Codeforces 839E Mother of Dragons
题 OvO http://codeforces.com/contest/839/problem/E (Codeforces Round #428 (Div. 2) - E) 解 首先,k肯定是要平均分 ...
- 【CF839E】Mother of Dragons 折半状压
[CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- CF839E Mother of Dragons 最大团 Bron-Kerbosch算法
题意简述 给你一个\(n\)个节点的无向图\(G=\{V,E\}\)的邻接矩阵\(g\)和每个点的点权为\(s_i\),且\(\sum_{i=1}^n s_i = K\),要你求出\(\mathrm{ ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- 22. CTF综合靶机渗透(十五)
靶机说明: Game of Thrones Hacking CTF This is a challenge-game to measure your hacking skills. Set in Ga ...
- 长春理工大学第十四届程序设计竞赛(重现赛)M.Orx Zone
链接:https://ac.nowcoder.com/acm/contest/912/M 题意: Daenerys Stormborn, 风暴中出生的丹尼莉丝,the Unburnt, 烧不死的,Qu ...
随机推荐
- 【批处理】IF ERRORLEVER语句顺序注意
@echo off dir d:\dddddd if errorlevel 1 goto 1 if errorlevel 0 goto 0 rem 两行if语句不可交换位置,否则失败了也会显示成功. ...
- 【java】缓冲字符字节输入输出流:java.io.BufferedReader、java.io.BufferedWriter、java.io.BufferedInputStream、java.io.BufferedOutputStream
BufferedReader最重要,因为有个方法public String readLine() package System输入输出; import java.io.BufferedReader; ...
- Android 开发,你遇上 Emoji 头疼吗?
在 Android 中,如果需要使用的到 Emoji 表情,你会发现在某些设备上,有一些 Emoji 表情会被以豆腐块 "☐" 的形式显示,这是因为当前设备并不支持这个 Emoji ...
- Xcode极速代码,征服Xcode
当谈论到iOS开发工具时,有一个肯定是所有iOS开发者都熟悉的,那就是Xcode.Xcode是使所有令人赞叹的iOS app成为可能的驱动力. Xcode能帮助我们完成非常多的事情,但是这也有点让人头 ...
- 502 VS 504
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/89 首先看一下概念: 502:作为网关或者代理工作的服务器尝试执 ...
- ArcGIS API for JavaScript 4.2学习笔记[18] 搜索小部件
这个例子很简单,作为开学后(暴露出学生党的本质)的开胃菜是再合适不过了. 不过,博主提前警告一下:接下来的例子会相当的长.烦.难.我还会用"引用"-"函数参数骨架&quo ...
- bzoj 4199: [Noi2015]品酒大会
Description 一年一度的"幻影阁夏日品酒大会"隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发"首席品酒家"和"首席猎手&quo ...
- Oracle添加记录的时候报错:违反完整性约束,未找到父项关键字
今天需要向一个没有接触过的一个Oracle数据库中添加一条记录,执行报错: 分析: 报错的根本原因:未找到父项关键字的原因是因为你在保存对象的时候缺失关联对象. 问题的解决思路:先保存关联对象后再保存 ...
- PHP 购物车 php闭包 array_walk
<?php class Cart { const PRICE_BUTTER = 1.00; const PRICE_MILK = 3.00; const PRICE_EGGS = 6.95; p ...
- 学习整理与细化(1)——Internet 的域名系统(domain name system)
2015-09-20 整理人:承蒙时光 如有错误欢迎指教O(∩_∩)O谢谢 1.作用:提供主机符号符名与IP地址之间转换服务也称域名服务: 2..域名系统的层次型结构命名机制(服务器地址): 计算机名 ...