码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1530(最大团)

时间:2017-01-24 20:12:21      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:queue   iostream   ace   pairs   bre   height   eof   image   log   

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.

问题描述:团就是最大完全子图。

给定无向图G=(V,E)。如果U技术分享V,且对任意u,v技术分享U 有(u,v) 技术分享 E,则称U 是G 的完全子图。

G 的完全子图U是G的团当且仅当U不包含在G 的更大的完全子图中,即U就是最大完全子图。

G 的最大团是指G中所含顶点数最多的团。

这里可使用加入DP后的优化算法

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
int n,path[61][61],s[61],ans,dp[61];
bool is_clique(const int end,const int point)
{
    int i;
    for (i=1;i<end;i++)
        if (!path[s[i]][point]) return false;
    return true;
}
void dfs(int depth,int now)
{
    if (depth+n-now+1<=ans||depth+dp[now]<=ans) return;
    int i;
    for (i=now;i<=n;i++)
    {
        if (is_clique(depth+1,i))
        {
            s[depth+1]=i;
            dfs(depth+1,i+1);
        }
    }
    if (depth>ans) ans=depth;
}
int main()
{
    while (~scanf("%d",&n))
    {
        if (n==0) break;
        int i,j;
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++) scanf("%d",&path[i][j]);
        memset(dp,0,sizeof(dp));
        ans=0;
        dp[n]=1;
        for (i=n-1;i>=1;i--)
        {
            s[1]=i;
            dfs(1,i+1);
            dp[i]=ans;
        }
        printf("%d\n",dp[1]);
    }
    return 0;
}

 

HDU1530(最大团)

标签:queue   iostream   ace   pairs   bre   height   eof   image   log   

原文地址:http://www.cnblogs.com/hnqw1214/p/6347680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!