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. [转帖]Docker 入门教程

    Docker 入门教程 http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html 自己学的还是太肤浅啊.. 作者: 阮一峰 日期: 201 ...

  2. C#与C++的区别

    C# 参考链接:https://www.runoob.com/csharp/csharp-tutorial.html ------------------C#数据类型----------------- ...

  3. 小a的强迫症 题解

    题面: 小a是一名强迫症患者,现在他要给一群带颜色的珠子排成一列,现在有N种颜色,其中第i种颜色的柱子有num(i)个.要求排列中第i种颜色珠子的最后一个珠子,一定要排在第i+1种颜色的最后一个珠子之 ...

  4. LC 200 Number of Islands

    问题描述 Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is ...

  5. llinux 进阶篇

    df 查看磁盘空间 df -h (加了之后就有单位了) free 指令,查看内存使用情况 free -m(表示一mb单位进行查看) head 查看一个文件的前n行,如果没有n 就默认为前10行 hea ...

  6. golang(9):网络编程 & redis

    网络编程 TCP/IP 协议: . TCP(传输控制协议) -- 应用程序之间通信 . UDP(用户数据包协议)-- 应用程序之间的简单通信 . IP(网际协议) -- 计算机之间的通信 . DHCP ...

  7. ZROI Day1 比赛解题报告

    ZROI Day1 比赛解题报告 版权原因不提供题面相关信息 序 前天晚上搞得比较晚,然后早上做题很没状态,刚看到T1发现没什么思路就有点慌,赶紧看了看T2,T3, 发现T3暴力很好打,T2想了一想可 ...

  8. Laravel 实现指定用户下的设备分页(与查询指定分类下的文章原理相同)

    <?php //控制器 namespace App\Http\Controllers\Api\User; use App\Http\Controllers\Controller; use Ill ...

  9. ubuntu下安装vue/cli提示No command 'vue' found

    通过官方指令 npm install -g @vue/cli 安装vue脚手架提示: No command 'vue' found, did you mean: Command 'vpe' from ...

  10. Nginx作为静态资源web服务之防盗链

    Nginx作为静态资源web服务之防盗链 首先,为什么需要防盗链,因为有些资源存在竞争对手的关系,比如淘宝的商品图片,不会轻易的让工具来爬虫爬走收集.但是如果使用防盗链,需要知道上一个访问的资源,然后 ...