请各位高手将详细注释写出来,谢谢,绝对给分!!!!!!!!!!!!
#include〈stdio.h〉#define  N 10void output(int color[])/*输出一种着色方案*/{ int i ;    for ( i = 0 ; i < N ; i++ )         printf( "%4d" , color[i] ) ;    printf( "\n" ) ;}int back( int *ip ,int color[] ) /*回溯*/{ int c = 4 ;    while ( c == 4 ){        if ( *ip <= 0 ) return 0 ;        --(*ip) ;        c = __(1)__ ;        color[*ip] = -1 ;    }     return c ;}/*检查区域i,对c种颜色的可用性*/int color0k( int i , int c , int[][N] , int color[ ] }{ int j ;    for ( j = 0 ; j < i ; j++ }        if ( __(2)__ )            return 0 ;    return 1 ;} /*为区域i选一种可着的颜色*/int select( int i ,int c ,int adj[][N] , int color[ ] ){ int k ;    for ( k = c ; k <= 4 ; k++ )        if ( colorOK( __(2)__ ) )            return k ;        return 0 ;}int coloring( int adj[][N] ) /*寻找各种着色方案*/{ int color[N] , i , c , cnt ;    for ( i = 0 ; i < N ; i++ ) color[i] = -1 ;    i = c = 0 ; cnt = 0 ;    while ( 1 ) {        if ( ( c = __(4)__ ) == 0 ){            c = back( &i , color) ;            if ( c == 0) return cnt ;        } else { __(5)__ ; i++ ;            if ( i == N ) {                    output(color) ;                    ++cnt ;                    c = back( &i , color ) ;                  } e1se c = 0 ;                }        }}void main(){ int adj[N][N] =             { {0,1,0,1,1,1,1,1,1,1},              {1,0,1,1,0,1,1,1,1,0},              {0,1,0,1,0,1,1,0,1,1},              {1,1,1,0,1,1,0,0,1,1},              {1,0,0,1,0,1,0,0,0,0},              {1,1,1,1,1,0,1,0,0,1},              {1,1,1,0,0,1,0,0,1,0},              {1,1,0,0,0,0,0,0,1,1},              {1,1,1,1,0,0,1,1,0,1},              {1,0,1,1,0,1,0,1,1,0}            } ;    printf( "共有%d组解.\n",coloring( adj ) ) ;}

解决方案 »

  1.   

    是水平考试题吧?猜中加分哦(1) color[*ip]
    (2) adj[i][j] != 0 && color[j] == c
    (3) i,k,adj,color
    (4) select (i,c+l,adj,color)
    (5) color[i]=c原题意:
    著名的四色定理指出任何平面区域图均可用四种颜色着色,使相邻区域着不同的颜色。本程序对给定的区域图找出所有可能的不超过四种颜色的着色方案。程序中用 1~4 表示四种颜色。要着色的 N 个区域用 0~N一1编号,区域相邻关系用 adj[][] 矩阵表示,矩阵的 i 行 j 列的元素为 1 ,表示区域 i 与区域 j 相邻;矩阵的 i 行 j 列的元素为 0 ,表示区域 i 与区域 j 不相邻。数组 color[] 用来存储着色结果, color[i] 的值为区域 i 所着颜色。