zoukankan      html  css  js  c++  java
  • 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
    ",dp[1]);
        }
        return 0;
    }
  • 相关阅读:
    第一章Struts1
    Java
    论坛入口forum.php
    【Discuz系列教程2】论坛入口forum.php
    【Discuz系列教程3】核心函数class_core.php
    discuz 系统函数库function_core注释
    java 每日习题(四)求101-200之间的素数
    java 每日习题(三)兔子问题
    java 每日习题(二) 用decimalFormat格式化输出
    java 每日习题(一)
  • 原文地址:https://www.cnblogs.com/hnqw1214/p/6347680.html
Copyright © 2011-2022 走看看