#include <stdio.h>
#define CITY_NUM 21

// data structure
//int r_color[CITY_NUM];
int r_color[CITY_NUM] = {0};
int city_connection[CITY_NUM][CITY_NUM]=
    { {0},
    {0,1,1,1,1,1,1},
    {0,1,1,1,1},
    {0,1,1,1,0,0,1},
    {0,1,1,0,1,1},
    {0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,0,1},
    {0,1,0,1,0,1,1,1,1,1},
    {0,0,0,0,0,0,1,1,1},
    {0,0,0,0,0,0,1,1,1,1,0,0,1},
    {0,0,0,0,0,1,1,0,1,1,0,0,1,1,1,0,1},
    {0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,0,0,0,1},
    {0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1},
    {0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,1,1},
    {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1},
    {0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1},
    {0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,0,1},
    {0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,1},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
    {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,1,1},
    {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1}};


int Feasible ( int city_connection[CITY_NUM][CITY_NUM], 
               int r_color[CITY_NUM],int current)
{                    /*���缘�前��色�����欠����*/
    int j;
    for ( j = 1; j<current; j++ )
        if ( city_connection[current][j] == 1 
             && r_color[j] == r_color[current] )
            return 0;    /*������������色��同*/
        return 1;
}

void M_Coloring ( int city_connection[CITY_NUM][CITY_NUM],
               int r_color[CITY_NUM], int sum, int current )
{
    int i;
    if ( current <= sum )/*������谐���*/
        for ( i=1; i<=4; i++)/*����每����色*/
        {
            r_color[current] = i;/*������色*/
            if ( Feasible(city_connection, r_color, current) )/*�����猿晒�*/
            {
                M_Coloring (city_connection, r_color, sum, current+1);/*�����
一������*/
                return;
            }
        }
}

void test()
{
    //Initialize_default();
    //Initialize_input_by_user();
    M_Coloring(city_connection, r_color, 20, 1);
    
    printf("\n");
    for( int i=1; i<=20; i++)
        printf( "%3d", r_color[i] );
    printf ("\n");
}

void main (void)
{
    test();
}
--


�� ��源:�����幕����� http://bbs.cqupt.edu.cn��[FROM: 172.16.38.155]