• POJ 1129


    #include<iostream>
    #include<stdio.h>
    #include<string>
    #define MAXN 60
    using namespace std;
    int max_clique(int n, int * * mat, int *ret) ;
    int main()
    {
        //freopen("acm.acm","r",stdin);
        int i;
        int ans;
        int j;
        string s;
        int num;
        int * * _m;
        int * ret;
        while(cin>>num)
        {
            if(num == 0)
                break;
            _m = new int * [num];
            ret = new int[num];
            for(i = 0; i < num; ++ i)
            {
                _m[i] = new int[num];
                memset(_m[i],0,sizeof(int)*num);
            }
        //for(i = 0; i < num; ++ i)
        //        for(j = 0; j < num; ++ j)
        //            cout<<_m[i][j]<<" ";
            for(i = 0; i < num; ++ i)
            {
                cin>>s;
                if(s.length() == 2)
                    continue;
                else
                {
                    for(j = 2; j < s.length(); ++ j)
                    {
                        _m[s[0] - 'A'][s[j] - 'A'] = 1;
                    }
                }
            }
        ans = max_clique(num,_m,ret);
        cout<<ans;
        if(ans == 1)
            cout<<" channel needed."<<endl;
        else
            cout<<" channels needed."<<endl;
        delete [] _m;
        delete ret;
        }
    }
    
    
    void clique(int n, int* u, int * * mat, int size, int& max, int& bb, int * res, int* rr, int* c) {
        int i, j, vn, v[MAXN];
        if (n) {
            if (size + c[u[0]] <= max) return;
            for (i = 0; i < n + size - max && i < n; ++ i) {
                for (j = i + 1, vn = 0; j < n; ++ j)
                    if (mat[u[i]][u[j]])
                        v[vn ++] = u[j];
                rr[size] = u[i];
                clique(vn, v, mat, size + 1, max, bb, res, rr, c);
                if (bb) return;
            }
        } else if (size > max) {
            max = size;
            for (i = 0; i < size; ++ i)
                res[i] = rr[i];
            bb = 1;
        }
    }
    
    int max_clique(int n, int * *mat, int * ret) {
        int max = 0, bb, c[MAXN], i, j;
        int vn, v[MAXN], rr[MAXN];
        for (c[i = n - 1] = 0; i >= 0; -- i) {
            for (vn = 0, j = i + 1; j < n; ++ j)
                if (mat[i][j])
                    v[vn ++] = j;
            bb = 0;
            rr[0] = i;
            clique(vn, v, mat, 1, max, bb, ret, rr, c);
            c[i] = max;
        }
        return max;
    }

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    云架构师进阶攻略(1)
    针对云主机卡死问题的定位分析方法
    让App飞久一点
    OC静态代码检查实战
    PAT 1010. 一元多项式求导
    PAT 1009. 说反话
    PAT 1008 数组元素循环右移问题
    PAT 1007. 素数对猜想
    PAT 1006 换个格式输出整数
    PAT 1005 继续(3n+1)猜想
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563286.html
Copyright © 2020-2023  润新知