E. Mother of Dragons

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

Input

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.

Output

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 .

Examples
Input
3 1
0 1 0
1 0 0
0 0 0
Output
0.250000000000
Input
4 4
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
Output
4.000000000000
Note

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()的使用】的更多相关文章

  1. Codeforces 839E Mother of Dragons(极大团)

    [题目链接] http://codeforces.com/contest/839/problem/E [题目大意] 现在有一些点,现在你有k的液体,随意分配给这些点, 当两个点有边相连的时候,他们能产 ...

  2. Codeforces 839E Mother of Dragons

    题 OvO http://codeforces.com/contest/839/problem/E (Codeforces Round #428 (Div. 2) - E) 解 首先,k肯定是要平均分 ...

  3. 【CF839E】Mother of Dragons 折半状压

    [CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...

  4. Codeforces Round #428 (Div. 2)E. Mother of Dragons

    http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...

  5. CF839E Mother of Dragons 最大团 Bron-Kerbosch算法

    题意简述 给你一个\(n\)个节点的无向图\(G=\{V,E\}\)的邻接矩阵\(g\)和每个点的点权为\(s_i\),且\(\sum_{i=1}^n s_i = K\),要你求出\(\mathrm{ ...

  6. Codeforces Round #428 (Div. 2) 题解

    题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...

  7. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  8. 22. CTF综合靶机渗透(十五)

    靶机说明: Game of Thrones Hacking CTF This is a challenge-game to measure your hacking skills. Set in Ga ...

  9. 长春理工大学第十四届程序设计竞赛(重现赛)M.Orx Zone

    链接:https://ac.nowcoder.com/acm/contest/912/M 题意: Daenerys Stormborn, 风暴中出生的丹尼莉丝,the Unburnt, 烧不死的,Qu ...

随机推荐

  1. iOS SVN出现的问题,在mac使用Cornerstone中无法提交提交失败处理。。。

    问题一: Description : An error occurred while contacting the repository. Suggestion : The server may be ...

  2. npm的使用总结

    npm常用命令 npm list 查看当前目录下已安装的包 npm root -g 查看全局安装的包的路径 npm help 查看全部命令 npm update/uninstall moduleNam ...

  3. Git远程库版本回滚

    在git的一般使用中,如果发现错误的将不想staging的文件add进入index之后,想回退取消,这就叫做git代码库回滚: 指的是将代码库某分支退回到以前的某个commit id.可以使用命令:g ...

  4. [Count the numbers satisfying (m + sum(m) + sum(sum(m))) equals to N]

    Given an integer N, the task is to find out the count of numbers M that satisfy the condition M + su ...

  5. gitlab 升级

    =============================================== 2017/10/21_第1次修改                       ccb_warlock = ...

  6. springBoot系列教程04:mybatis及druid数据源的集成及查询缓存的使用

    首先说下查询缓存:查询缓存就是相同的数据库查询请求在设定的时间间隔内仅查询一次数据库并保存到redis中,后续的请求只要在时间间隔内都直接从redis中获取,不再查询数据库,提高查询效率,降低服务器负 ...

  7. csv文件转json

    http://stackoverflow.com/questions/19766266/directly-convert-csv-file-to-json-file-using-the-jackson ...

  8. Spring3.x企业开发应用实战读书笔记 —— 第三章IoC容器概述

    声明:    本篇博客绝大多数内容为<Spring3.x企业开发应用实战>一书原内容,所有版权归原书作者所有!,仅供学习参考,勿作他用! 3.2 相关Java基础知识 Java语言允许通过 ...

  9. Xamarin.android Activity动画切换效果实现

    http://blog.csdn.net/esunshine1985/article/details/44302903 1.在Resources--values下新建styles.xml,添加内容如下 ...

  10. 如何用css写打印样式

    打印样式 打印样式就是针对网页被打印时设置给文档的样式,由于打印时是显示在纸上,跟屏幕还是有区别的,对于有打印需求的网页往往需要设置专门的打印样式来适配页面. @media print 声明自己是打印 ...