【HDU1530】【ZOJ1492】Maximum Clique
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;
}