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

(最大团 模板) hdu 1530

时间:2015-04-02 09:06:00      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

Maximum Clique

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2933    Accepted Submission(s): 1570


Problem Description
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.
 

 

Input
Input contains multiple tests. For each test:

The first line has one integer n, the number of vertex. (1 < n <= 50)

The following n lines has n 0 or 1 each, indicating whether an edge exists between i (line number) and j (column number).

A test with n = 0 signals the end of input. This test should not be processed.
 

 

Output
One number for each test, the number of vertex in maximum clique.
 

 

Sample Input
5 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0
 

 

Sample Output
4
 

 

Author
CHENG, Long
 

 

Source
 

 

Recommend
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
int n,mp[55][55],vis[55],cnt,bestn;
void dfs(int x)
{
    if(x>n)
    {
        if(cnt>bestn)
            bestn=cnt;
        return ;
    }
    bool ok=true;
    for(int i=1;i<x;i++)
    {
        if(vis[i]&&!mp[i][x])
        {
            ok=false;
            break;
        }
    }
    if(ok)
    {
        vis[x]=1;
        cnt++;
        dfs(x+1);
        cnt--;
    }
    if(cnt+n-x>bestn)
        vis[x]=0,dfs(x+1);
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
            break;
        cnt=bestn=0;
        memset(vis,0,sizeof(vis));
        memset(mp,0,sizeof(mp));
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                scanf("%d",&mp[i][j]);
        }
        dfs(1);
        printf("%d\n",bestn);
    }
    return 0;
}

  

(最大团 模板) hdu 1530

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4385849.html

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