HDU1530 Maximum Clique & ZOJ 1492 Maximum Clique

2 篇文章 0 订阅
1 篇文章 0 订阅

HDU1530 Maximum Clique&ZOJ 1492 Maximum Clique

Position:


List

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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值