HDU ACM 1530 Maximum Clique->最大团

分析:最大团的模版题,DFS深搜。

#include<iostream>
using namespace std;

#define N 55
int map[N][N];
int set[N];
int max;

bool IsConnect(int end,int v)
{
	int i;

	for(i=0;i<end;i++)
		if(!map[set[i]][v])
			return false;
	return true;
}

void DFS(int depth,int u,int n)
{
	int i;

	if(depth+(n-(u-1))<=max)  //剪枝,后面不比前面的大则不用找了
		return ;

	for(i=u;i<=n;i++)
		if(IsConnect(depth,i))
		{
			set[depth]=i;
			DFS(depth+1,i+1,n);    //递归搜索后序节点
		}

	if(depth>max)       //更新最大值
		max=depth;
}

int main()
{
	int n,i,j;

	while(scanf("%d",&n)==1 && n)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&map[i][j]);

		max=0;
		DFS(0,1,n);             //从第0层第一个顶点开始搜
		printf("%d\n",max);
	}
	return 0;
}
时间: 2024-10-13 04:28:36

HDU ACM 1530 Maximum Clique->最大团的相关文章

hdu 1530 Maximum Clique_最大团模板

题目链接 题意:给你一个有向图,求最大完全子图. 思路:套最大团模板 #include<stdio.h> #define MAXN 100 int n,map[MAXN][MAXN],best,num[MAXN]; bool dfs(int *tmp,int total,int cnt){ int i,j,k,a[MAXN]; if(!total){ if(best<cnt){ best=cnt; return true; } return false; } for(i=0;i<t

hdu1530 Maximum Clique,最大团 , DP,邻接矩阵

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. #include <cstdio> #include <cstring> #include

最大团问题(Maximum Clique Problem, MCP)

概述: 最大团问题(Maximum Clique Problem, MCP)是图论中一个经典的组合优化问题,也是一类NP完全问题.最大团问题又称为最大独立集问题(Maximum Independent Set Problem).目前,求解MCP问题的算法主要分为两类:确定性算法和启发式算法.确定性算法有回溯法.分支限界法等,启发式算法.蚁群算法.顺序贪婪算法.DLS-MC算法和智能搜索算法等. 问题描述: 给定无向图G=(V,E),其中V是顶点集:E是V边集.如果U属于V,且对任意两个顶点u,v

Maximum Clique

Maximum Clique Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 92 Accepted Submission(s): 60   Problem Description Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex

杭电HDU ACM Uncle Tom&#39;s Inherited Land*(二分图匹配 建模)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2496    Accepted Submission(s): 1028 Special Judge Problem Description Your old uncle Tom inherited a piece of land f

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务