OvO http://codeforces.com/contest/839/problem/E

  (Codeforces Round #428 (Div. 2) - E)

  首先,k肯定是要平均分给这图中的一个最大团,

  粗略的证明如下

  

  然后,可以通过BronKerbosch算法求极大团,然后从极大团中找出最大的团,就是最大团,

  All表示当前团中元素的集合,Some表示候选元素的集合(Some中任意元素都与All中所有元素有边),None元素表示已选的元素的集合(None中任意元素与All中的所有元素都有边)(None是用于去重的),

  当Some和None都为空的时候,All就是一个极大团。

  u节点用于优化。

  具体实现在代码中,这算法贼简洁。

  (思路来源于瞟了一眼某大佬的代码)

  

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector> using namespace std; const int N=55;
const int M=11111; struct node{
int u,v;
int next;
}edge[N*N]; int n,k,num;
int head[N];
int g[N][N];
int mx;
int All[M][N],Some[M][N],None[M][N]; void addedge(int u,int v)
{
edge[num].u=u;
edge[num].v=v;
edge[num].next=head[u];
head[u]=num++;
} void init()
{
mx=0;
num=0;
memset (head,-1,sizeof(head));
memset(g,0,sizeof(g));
} void BronKerbosch(int id,int lenAll,int lenSome,int lenNone)
{
// cout<<"id: "<<id<<" lenAll: "<<lenAll<<" lenSome: "<<lenSome<<" lenNone: "<<lenNone<<endl;
if(lenSome==0 && lenNone==0)
{
if(lenAll>mx)
mx=lenAll;
return ;
}
if(lenSome==0)
return ;
int i,j,u,v,tid,tlenAll,tlenSome,tlenNone;
u=Some[id][1]; tid=id+1;
for(i=1;i<=lenSome;i++)
{
v=Some[id][i];
if(g[u][v]) continue;
tlenAll=lenAll+1;
for(j=1;j<=lenAll;j++)
All[tid][j]=All[id][j];
All[tid][tlenAll]=v;
tlenSome=0;
for(j=1;j<=lenSome;j++)
if(g[v][Some[id][j]])
Some[tid][++tlenSome]=Some[id][j];
tlenNone=0;
for(j=1;j<=lenNone;j++)
if(g[v][None[id][j]])
None[tid][++tlenNone]=None[id][j];
BronKerbosch(tid,tlenAll,tlenSome,tlenNone);
}
} void solve()
{
int i,j;
for(i=1;i<=n;i++)
Some[0][i]=i;
BronKerbosch(0,0,n,0);
} int main()
{
int i,j;
init();
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&g[i][j]);
if(g[i][j]==1)
addedge(i,j);
}
solve();
double ans=1.0*(mx-1)*mx/2*(1.0*k/mx)*(1.0*k/mx);
printf("%.10lf\n",ans);
return 0;
}

  

Codeforces 839E Mother of Dragons的更多相关文章

  1. Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】

    E. Mother of Dragons time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...

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

    [题目链接] http://codeforces.com/contest/839/problem/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. Wordpress 所有 hook 钩子

    muplugins_loaded 在必须使用的插件加载之后. registered_taxonomy 对于类别,post_tag 等 Registered_post_type 用于帖子,页面等 plu ...

  2. Oracle的查询-单行查询

    单行函数:作用于一行,返回一个值 多行函数:作用于多行,返回一个值 字符函数 --小写变大写 select upper('yes') from dual; --YES --大写变小写 select u ...

  3. linux用户和组 之 用户管理

    一. linux 用户和组的基本介绍 1.linux下 有三种用户: 1. root: 权限最大的. 2. 系统用户: UID小于1000的.系统服务管理用户,一般是不允许登录系统的.(比如mysql ...

  4. Log4j2日志配置详解(2)

    Log4j2日志配置系列之2 1.Configuration 在应用程序代码中插入日志请求需要相当多的计划和工作.观察显示,大约4%的代码用于日志记录.因此,即使是中等大小的应用程序也会在其代码中嵌入 ...

  5. Web安全小结之后端

  6. FFmpeg4.0笔记:封装ffmpeg的解封装功能类CDemux

    Github https://github.com/gongluck/FFmpeg4.0-study/tree/master/Cff CDemux.h /*********************** ...

  7. CentOS7 Python3上安装paramiko

    1. CentOS 7下安装Python3.5 CentOS7默认安装了python2.7.5,要用 Python3需要自己手动安装.注意不要删除python2. 1.1 下载python3源码包 w ...

  8. HTML5之历史记录(实现的当页面应用路由器的底层)

    history hashchange与popstate 一.history history.back():加载history列表中的前一个URL history.forward():加载history ...

  9. Linux 永久挂载镜像文件和制作yum源

    Linux mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件. 1.镜像挂载到系统指定目录下:[root@master cdrom]#  mount -t auto  /mnt/c ...

  10. Java注解【一、概述】

    前面几篇Java学习笔记都是半夜写的,比较伤身体,今天开始想调整生物钟,早上起来学2小时,看看能坚持多久 本周目标: 1.JavaJDBC使用 2.JavaWeb编程 3.Java框架基础(反射+注解 ...