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;
    }
  • 相关阅读:
    ros论坛
    python--dict和set类型--4
    python--条件判断和循环--3
    python--list和tuple类型--2
    Unicode与UTF-8互转(C语言实现)
    spring mvc 返回JSON数据
    值得学习的C语言开源项目和库
    mudos源码分析
    Freemarker使用总结
    Maven详解
  • 原文地址:https://www.cnblogs.com/hnqw1214/p/6347680.html
Copyright © 2011-2022 走看看