资源简介

最大团问题代码实现 简单易懂 适合算法学习

资源截图

代码片段和文件信息

#include
#include
#include
typedef struct 
{
    int maxlen;//对应各个顶点最大团的顶点个数
    int ar[6][10];//最大团方案
    int num;//各顶点的所有团的个数
}Arr;
void Turn(Arr m[20]int a1[20][20]int a2[20][20]int iint vertex)//将无向图矩阵转化为三维数组形式寻找所有最大团
{
    int jk(1)temlen(1)m1m2;
    int flag=1;
    m[i].maxlen=0;
        for(j=1;j<=vertex-1;j++)
            if(a1[a2[i][0]][a2[i][j]]!=1)
                a2[i][j]=0;        //更新相邻顶点矩阵数组
    for(j=1;j        for(k=j+1;k<=vertex-1;k++)
            if(a1[a2[i][j]][a2[i][k]]!=1)
                
            {
                flag=0;
                m1=j;
                m2=k;
                break;
            }//判断是否为此顶点的团
            if(flag)
            {
                m[i].num++;
                            for(j=1;j<=vertex-1;j++)
                            {
                                m[i].ar[m[i].num][j]=a2[i][j];
                                if(a2[i][j]!=0)
                                a1[a2[i][j]][i]=0;
                                if(a2[i][j])
                                    len++;
                            }
                                if(m[i].maxlen                                {
                                    m[i].maxlen=len;
                                    len=0;
                                }            
            }
            else   //递归调用回溯寻找最大团
            {
                tem=a2[i][m1];
                a2[i][m1]=0;
                Turn(ma1a2ivertex);
                a2[i][m1]=tem;
                tem=a2[i][m2];
                a2[i][m2]=0;
                Turn(ma1a2ivertex);
                a2[i][m2]=tem;
            }
}
void Output(Arr m[20]int a1[20][20]int a2[20][20]int maxint vertex)//

评论

共有 条评论