【HDU - 1530】Maximum Clique(最大团问题,图论)

题干:

Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex pairs v1, v2 in v, there exists an edge (v1, v2) in e. Maximum clique is the clique that has maximum number of vertex. 

Input

Input contains multiple tests. For each test: 

The first line has one integer n, the number of vertex. (1 < n <= 50)

The following n lines has n 0 or 1 each, indicating whether an edge exists between i (line number) and j (column number). 

A test with n = 0 signals the end of input. This test should not be processed. 

Output

One number for each test, the number of vertex in maximum clique. 

Sample Input

5
0 1 1 0 1
1 0 1 1 1
1 1 0 1 1
0 1 1 0 1
1 1 1 1 0
0

Sample Output

4

解题报告:

  暴力dfs+剪枝。(然而剪枝并不能快多少,也就快了200ms左右)

AC代码:(4134ms)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 55 + 5;
int a[MAX][MAX]; 
int bk[MAX];
int n,ans;
void dfs(int cur,int tmp) {if(cur == n+1) {ans = max(ans,tmp);return;}int tar = cur+1;dfs(tar,tmp);for(int j = 1; j<=tmp; j++) {if(a[tar][bk[j]] == 0) return;}bk[tmp+1] = tar;dfs(tar,tmp+1);
}
int main()
{while(~scanf("%d",&n) && n) {ans = 0;memset(a,0,sizeof a);for(int i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) scanf("%d",&a[i][j]);}dfs(0,0);printf("%d\n",ans);}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440304.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Apollo自动驾驶入门课程第①讲—无人驾驶概览

目录 1. 全面了解自动驾驶主要模块 2. 了解无人车的运作方式 3. 开放式软件栈 4. 本节其他重点 本文转自微信公众号&#xff1a;Apollo开发者社区 原创&#xff1a; 阿波君 Apollo开发者社区 8月1日 在Apollo 3.0发布的同时&#xff0c;我们面向更多对自动驾驶感兴趣的开发…

【CF - 699C】 Vacations (日程安排 dp)

题干&#xff1a; Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day…

《TCP/IP详解》学习笔记(五):IP选路、动态选路

静态 IP 选路 1一个简单的路由表 选路是 IP 层最重要的功能之一。前面的部分已经简单的讲过路由器是如何根据 IP 数据包的 IP 地址来选择路由的。 这里就不重复了。首先来看看一个简单的系统路由表&#xff1a; 对于一个给定的路由器,可以打印出五种不同的 flag&#xff1a; …

LeetCode刷题实战(43):Multiply Strings

题目描述&#xff1a; 43Multiply Strings28.7%Medium Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: Input: num1 "2", num2 "3" Output…

【2018山东省赛 - A】Anagram(贪心,费用流,KM算法)

题干&#xff1a; Problem Description Orz has two strings of the same length: A and B. Now she wants to transform A into an anagram of B (which means, a rearrangement of B) by changing some of its letters. The only operation the girl can make is to “incr…

【2018ACM山东省赛 - B】Bullet(二分 + 二分图匹配,匈牙利算法,卡常)

题干&#xff1a; Problem Description In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an nnn \times nnn m…

13.Data Leakage

本教程是ML系列的一部分。在此步骤中&#xff0c;你将学习什么是data leakage及如何预防它。 What is Data Leakage 数据泄漏是数据科学家需要理解的最重要问题之一。 如果您不知道如何防止它&#xff0c;则会频繁出现泄漏&#xff0c;并且会以最微妙和危险的方式破坏您的模…

0.Overview----Machine Learning

本文为Kaggle Learn的Machine Learning课程的中文翻译&#xff0c;原文链接为&#xff1a;https://www.kaggle.com/learn/machine-learning 1.How Models Work The first step if youre new to machine learning 2.Explore Your Data Load data and set up your environment …

【2018ACM山东省赛 - C】Cities(最小生成树变形优化,贪心思维)

题干&#xff1a; Problem Description There are nnn cities in Byteland, and the ithi_{th}ith​ city has a value aia_iai​. The cost of building a bidirectional road between two cities is the sum of their values. Please calculate the minimum cost of connec…

项目总结1:微信扫码自动识别设备类型并跳转到相应的应用下载页面(apk或App Store)之解决方案

问题分析&#xff1a;普通页面一般无法调用微信的扫一扫接口&#xff0c;从而否定通过微信扫一扫功能给我们判断当前扫码的设备类型。 解决方案&#xff1a;通过应用下载页面自身来获取当前访问的客户端设备类型&#xff08;iPhone、Android、iPad&#xff09;&#xff0c;然后…

《TCP/IP详解》学习笔记(六):UDP 协议

UDP 简要介绍 UDP 是传输层协议&#xff0c;和 TCP 协议处于一个分层中&#xff0c;但是与 TCP 协议不同&#xff0c;UDP 协议并不提供超时重传&#xff0c;出错重传等功能&#xff0c;也就是说其是不可靠的协议。 UDP 协议头 1UDP 端口号 由于很多软件需要用到 UDP 协议&am…

【2018ACM山东省赛 - E】Sequence(树状数组,思维,优化)

题干&#xff1a; We define an element aia_iai​ in a sequence "good", if and only if there exists a j(1≤j<i)j(1\le j < i)j(1≤j<i) such that aj<aia_j < a_iaj​<ai​. Given a permutation ppp of integers from 111 to nnn. Remove …

Apollo自动驾驶入门课程第②讲 — 高精地图

目录 1. 高精地图与传统地图 2. 高精地图与定位、感知规划的关系 2.1 高精地图用于定位 2.2 高精地图用于感知 2.3 高精地图用于规划 3. Apollo高精度地图与构建 3.1 Apollo高精地图 3.2 Apollo高精地图的构建 本文转自微信公众号&#xff1a; Apollo开发者社区 原创&a…

项目总结2:ionic3开发跨平台App如何设置和替换应用图标及启动图

前言&#xff1a; 和原生开发一样&#xff0c;ionic官方提供的设置方式也很简单&#xff0c;只不过多了一个步骤&#xff1a;基于ionic命令的方式自动修改全局的配置文件config.xml。 设置或替换应用图标和应用启动图&#xff1a; 把UI提供的图标拿过来改成特定的名称"i…

【2018ACM山东省赛 - G】Games(Nim博弈 + dp)

题干&#xff1a; Problem Description Alice and Bob are playing a stone game. There are nnn piles of stones. In each turn, a player can remove some stones from a pile (the number must be positive and not greater than the number of remaining stones in the …

LeetCode刷题实战(13):Roman to Integer

题目描述&#xff1a; 13 Roman to Integer 49.5%Easy Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D …

项目总结3:ionic3开发的App在启动过程中部分手机出现白屏或黑屏问题之终极解决方案

问题场景&#xff1a;采用ionic3开发的App&#xff0c;当项目比较大的时候&#xff0c;会出现部分真机设备在启动的过程中有白屏或黑屏的情况。 原因预测&#xff1a;个别手机&#xff0c;尤其是安卓手机的性能比较差&#xff0c;App在启动后进入首页或登录页前的初始化工作还…

1.Intro to Deep Learning and Computer Vision

Intro 这是Kaggle深度学习教育课程的第一课。 在本课程结束后&#xff0c;您将了解卷积。 卷积是计算机视觉&#xff08;以及许多其他应用程序&#xff09;中深度学习模型的基本构建块。 之后&#xff0c;我们将很快开始使用世界一流的深度学习模型。 Lesson [1] from IPy…

【POJ - 2253】Frogger(floyd,或 部分瓶颈生成树的最大边)

题干&#xff1a; 湖中有n块石头&#xff0c;编号从1到n&#xff0c;有两只青蛙&#xff0c;Bob在1号石头上&#xff0c;Alice在2号石头上&#xff0c;Bob想去看望Alice&#xff0c;但由于水很脏&#xff0c;他想避免游泳&#xff0c;于是跳着去找她。但是Alice的石头超出了他…

SpringMVC常用的视图接口分类及实现类

SpringMVC中常用的视图接口分类及对应的实现类&#xff1a; URL资源视图&#xff1a;InternalResourceView、JstlView 文档视图&#xff1a;AbstractExcelView、AbstractPdfView 报表视图&#xff1a;ConfigurableJsperReportsView等JasperReports报表技术的视图 JSON视图&…