hdu1530 Maximum clique (ask for maximum group template problem)

Source: Internet
Author: User
Tags bool


link:http://acm.hdu.edu.cn/showproblem.php?pid=1530

Maximum Clique Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3142 Accepted Submission (s): 1650


Problem Description Given a graph G (V, E), a clique is a sub-graph G (V, e), so the for all vertex pairs v1, v2 in V, ther E exists an edge (V1, v2) in E. Maximum clique is the Clique, which 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 have n 0 or 1 each, indicating whether a edge exists between I (line number) and J (column number).

A Test with n = 0 signals the end of input. This test should is not 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 ZOJ Monthly, February 2003

AC Code:

#include <cstdio> #include <cstring> #define N 1010/* Max group = maximum number of independent sets of the complement G ——— > maximum independent number of sets = Complement G ' Max Group *//MAX Group template bool a[n][n];//a for the adjacency table of the graph (starting from 1) int ans, cnt[n], group[n], N, M, Vis[n];//ans represents the largest regiment, Cnt[n] represents the number of nodes of the current largest regiment, Group[n] is used to find a maximum set of bool D
    FS (int u, int pos)//u is a deep search depth (the position of the first layer of the current deep search tree) {int I, J;
             for (i = u+1; I <= n; i++)//enumerate vertices in ascending order {if (Cnt[i]+pos <= ans) return 0;//prune if (A[u][i]) { 
            Compare with current group elements, take non-n (i) for (j = 0; J < Pos; j + +) if (!a[i][vis[j]) break; if (j = = pos) {//If empty, then all are adjacent to I, then I join the largest regiment Vis[pos] = i;//Deep Search level is also the maximum number of vertices, vis[pos] = i means the current PO    
            The largest group element of S Small is I (because it is enumerated vertices in ascending order) if (Dfs (i, pos+1)) return 1; }}} if (pos > Ans) {for (i = 0; i < POS; i++) Group[i] = V Is[i];
            Update Max group element ans = pos;    
    return 1;
} return 0; } voidMaxclique ()//ask for the largest group {ans=-1;
        for (int i=n;i>0;i--) {vis[0]=i;
        DFS (i,1);
    Cnt[i]=ans;
    }} int main () {//freopen ("D:\in.txt", "R", stdin);
    int T;
    scanf ("%d", &t);
        while (~SCANF ("%d", &n)} {if (n==0) break;
        scanf ("%d%d", &n,&m);
        int x, y;
        memset (A, 0, sizeof (a));
            /*for (int i = 0; i < m; i++) {scanf ("%d%d", &x,&y);
        A[x][y] = a[y][x] = 1; 
		The}*/////adjacent vertices are connected to each other, and the model is converted to the maximum independent set of the graph.  Requires the largest independent set of the original image, converted to the largest regiment of the complement graph of the original (maximum number of vertices = maximum independent set of the complement) for (int i = 1; I <= n; i++)//The complement of the original image for (int j = 1; J <= N;
        J + +) scanf ("%d", &a[i][j]);
        Maxclique ();//For Maximum Regiment if (ans < 0) ans = 0;//ans represents max Group printf ("%d\n", ans); /*for (int i = 0; i < ans; i++) printf (i = = 0?) "%d": "%d", Group[i]);//group[n] used to find a maximum group if (ans > 0) puts ("");


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.