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
  1. 3 1
    0 1 0
    1 0 0
    0 0 0
Output
  1. 0.250000000000
Input
  1. 4 4
    0 1 0 1
    1 0 1 0
    0 1 0 1
    1 0 1 0
Output
  1. 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代码:

  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. const int N = ;
  4. const double eps = 1e-;
  5. int n , k;
  6. long long graph[N];
  7. double ans;
  8. int clique;
  9. int bitcnt[ << ];
  10. void solve(long long mask , int cur){
  11. clique = max(clique , cur);
  12. int idx = -;
  13. int mx = ;
  14. for(int i = ; i <= n ; ++i){
  15. if(!((mask >> i) & )){
  16. continue;
  17. }
  18. int tmp = __builtin_popcountll(graph[i] & mask);
  19. if(idx == - || tmp > mx){
  20. mx = tmp;
  21. idx = i;
  22. }
  23. }
  24. if(idx == -){
  25. return;
  26. }
  27. clique = max(clique , cur + );
  28. if(mx + + cur <= clique){
  29. return;
  30. }
  31. solve((mask ^ (1LL << idx)) & graph[idx] , cur + );
  32. solve(mask ^ (1LL << idx) , cur);
  33. }
  34. int main(){
  35. scanf("%d %d" , &n , &k);
  36. for(int i = ; i <= n ; ++i){
  37. int tmp;
  38. graph[i] = ;
  39. for(int j = ; j <= n ; ++j){
  40. scanf("%d" , &tmp);
  41. graph[i] |= (1LL << j) * tmp;
  42. }
  43. }
  44. long long mask = ;
  45. for(int i = ; i <= n ; ++i){
  46. mask |= 1LL << i;
  47. }
  48. clique = ;
  49. solve(mask , );
  50. ans = (1.0 * k * k) / (1.0 * clique * clique);
  51. ans *= clique * (clique - );
  52. ans /= ;
  53. printf("%.6lf\n" , ans);
  54. }

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. JMeter循环控制器循环次数使用变量控制注意事项

    1.进入循环控制器之前变量要有值: 2.BeanShell处理文件,读取行数,赋值给变量,要有相应的Sampler,不然脚本不会运行. 对于单个线程来说,假如设置了循环2次,线程启动后,运行结束,此时 ...

  2. iOS常见的几种加密方法(base64.MD5.Token传值.系统指纹验证。。加密)

    普通加密方法是讲密码进行加密后保存到用户偏好设置中 钥匙串是以明文形式保存,但是不知道存放的具体位置 一. base64加密 base64 编码是现代密码学的基础 基本原理: 原本是 8个bit 一组 ...

  3. Kafka详细的设计和生态系统

    欢迎大家前往云加社区,获取更多腾讯海量技术实践干货哦~ 译者:人工智能资讯小编 本译文自Jean-Paul Azar 在 https://dzone.com 发表的 Kafka Detailed De ...

  4. 每周.NET前沿技术文章摘要(2017-05-24)

    汇总国外.NET社区相关文章,覆盖.NET ,ASP.NET等内容: .NET Free eBook/Guide on '.NET Microservices – Architecture for C ...

  5. android操作系统在itop4412开发板上的烧写

    ITOP4412启动模式: 1.EMMC启动模式:拨码开关1-3为011 2.SD卡启动模式:拨码开关1-3为100uboot:初始化内存控制器,访问存储器,把操作系统内核从存储器读取出来放到内存中, ...

  6. [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 ...

  7. bzoj 1801: [Ahoi2009]chess 中国象棋

    Description 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮. 请问有多少种放置方法,中国像棋中炮的行走方式大家应该很清楚吧. Input 一行包含两个整数N, ...

  8. Nginx 错误处理方法: bind() to 0.0.0.0:80 failed

    Nginx 错误处理方法: bind() to 0.0.0.0:80 failed 今天启动window上的nginx总是报错 错误信息是bind() to 0.0.0.0:80 failed (10 ...

  9. maven 打包Could not resolve dependencies for project和无效的目标发行版: 1.8

    1.maven 打包Could not resolve dependencies for project 最近项目上使用的是idea ide的多模块话,需要模块之间的依赖,比如说系统管理模块依赖授权模 ...

  10. jQuery 实现无限任意添加下拉菜单

    新学jQuery还有很多没学,今天做了个下拉菜单,按照自己的思想结合学的基础效果实现一款可以任意添加层数的下拉菜单,如果有什么建议,欢迎指教啦啦啦 我喜欢备注细一些,这样给自己也是一种理解和方便回顾哈 ...