HDU1530(最大团)

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)。如果UV,且对任意u,vU 有(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;
}

 

转载于:https://www.cnblogs.com/hnqw1214/p/6347680.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值