Position:

Description

  • 大意:给了一个最多包含 50 个点的无向图,让求这个图中最大团所包含的的点的数量

Solution

最大团模板题,不懂算法→详情参考MaximumClique最大团问题

Code

// <MaximumClique.cpp> - Mon Sep 19 20:59:48 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
struct MAX_CLIQUE{
static const int N=60;
bool G[N][N];
int n,Max[N],Alt[N][N],ans;
bool DFS(int cur,int tot){
if(!cur){
if(tot>ans){ans=tot;return 1;}
return 0;
}
for(int i=1;i<=cur;i++){
if(cur-i+tot+1<=ans)return 0;
int u=Alt[tot][i],nxt=0;
if(Max[u]+tot<=ans)return 0;
for(int j=i+1;j<=cur;j++)
if(G[u][Alt[tot][j]])Alt[tot+1][++nxt]=Alt[tot][j];
if(DFS(nxt,tot+1))return 1;
}
return 0;
}
int MaxClique(){
ans=0,memset(Max,0,sizeof(Max));
for(int i=n;i;i--){
int cur=0;
for(int j=i+1;j<=n;j++)
if(G[i][j])Alt[1][++cur]=j;
DFS(cur,1);
Max[i]=ans;
}
return ans;
}
void read(){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
G[i][j]=gi();
}
}Group;
int main()
{
freopen("MaximumClique.in","r",stdin);
freopen("MaximumClique.out","w",stdout);
while(Group.n=gi(),Group.n){
Group.read();
printf("%d\n",Group.MaxClique());
}
return 0;
}

【HDU1530】【ZOJ1492】Maximum Clique的更多相关文章

  1. 【最大团】【HDU1530】【Maximum Clique】

    先上最大团定义: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题,在国际上已有广泛的研究,而国内对MCP问题的研究则还处于起步 ...

  2. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  3. 【Java并发编程实战】-----“J.U.C”:ReentrantReadWriteLock

    ReentrantLock实现了标准的互斥操作,也就是说在某一时刻只有有一个线程持有锁.ReentrantLock采用这种独占的保守锁直接,在一定程度上减低了吞吐量.在这种情况下任何的"读/ ...

  4. 【Java并发编程实战】-----“J.U.C”:Semaphore

    信号量Semaphore是一个控制访问多个共享资源的计数器,它本质上是一个"共享锁". Java并发提供了两种加锁模式:共享锁和独占锁.前面LZ介绍的ReentrantLock就是 ...

  5. 【一天一道LeetCode】#122. Best Time to Buy and Sell Stock II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Say you ...

  6. 【一天一道LeetCode】索引目录 ---C++实现

    [一天一道LeetCode]汇总目录 这篇博客主要收藏了博主所做题目的索引目录,帮助各位读者更加快捷的跳转到对应题目 目录按照难易程度:easy,medium,hard来划分,读者可以按照难易程度进行 ...

  7. 【一天一道LeetCode】#55. Jump Game

    一天一道LeetCode系列 (一)题目 Given an array of non-negative integers, you are initially positioned at the fi ...

  8. 【Python】【容器 | 迭代对象 | 迭代器 | 生成器 | 生成器表达式 | 协程 | 期物 | 任务】

    Python 的 asyncio 类似于 C++ 的 Boost.Asio. 所谓「异步 IO」,就是你发起一个 IO 操作,却不用等它结束,你可以继续做其他事情,当它结束时,你会得到通知. Asyn ...

  9. day41 python【事物 】【数据库锁】

    MySQL[五] [事物 ][数据库锁]   1.数据库事物 1. 什么是事务  事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性 ...

  10. 网络工程师岗位基础面试题【适用于CCNA/CCNP基础】

    网络工程师岗位基础面试题[适用于CCNA/CCNP基础] 1: 交换机是如何转发数据包的?交换机通过学习数据帧中的源MAC地址生成交换机的MAC地址表,交换机查看数据帧的目标MAC地址,根据MAC地址 ...

随机推荐

  1. Spring框架系列(七)--Spring常用注解

    Spring部分: 1.声明bean的注解: @Component:组件,没有明确的角色 @Service:在业务逻辑层使用(service层) @Repository:在数据访问层使用(dao层) ...

  2. 配置redis三主三从

    主从环境 centos7.6 redis4.0.1 主 从 192.168.181.139:6379 192.168.181.136:6379 192.168.181.136:6380 192.168 ...

  3. crontab定时清理日志

    1.创建shell脚本 vi test_cron.sh #!/bin/bash#echo "====`date`====" >> /game/webapp/test_c ...

  4. 如何使用fio模拟线上环境

    线上表现 这里我想通过fio来模拟线上的IO场景,那么如何模拟呢? 首先使用iostat看线上某个盘的 使用情况,这里我们需要关注的是 avgrq-sz, avgrq-qz. #iostat -dx ...

  5. CodeForces 【20C】Dijkstra?

    解题思路 heap+Dijkstra就能过.注意边是双向边,要用long long. 附上代码 #include <iostream> #include <queue> #in ...

  6. Centos7安装MySQL5.7(yum)

    本人尝试过使用源码安装方式,那叫一个头疼,各种问题,于是采用yum方式安装,没想到如此简单: 此服务器是刚买的,所以以前没有安装过mysql,如果以前安装过mysql的,好像要卸载干净再安装(其实我也 ...

  7. http怎么做自动跳转https

    Nginx版本 server { listen       80; server_name  localhost; rewrite ^(.*)$ https://$host$1 permanent; ...

  8. linux more-显示文件内容,每次显示一屏

    博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作.more名单中 ...

  9. Pygame游戏开发入门(1)-开发框架

    pygame库的安装 pip install pygame pygame最小开发框架 #Pygame Hello World Game import pygame,sys #引入pygame和sys( ...

  10. C. Day at the Beach

    codeforces 599c C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the be ...