日期:2014-05-17  浏览次数:21052 次

骑士旅行问题 C#出现堆栈溢出
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public static int o=0;
        //定义步数
        public static int step = 0;
        //定义走法
        public static int[] a = { -2, 2, -1, 1, -2, 2, -1, 1 };
        public static int[] b = { -1, -1, -2, -2, 1, 1, 2, 2 };
        public static int[] dk = {0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0, 
                   0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0,
                   0,0,0,0,0,0,0,0};
        static void Main(string[] args)
        {
            
            
           
            //初始化棋盘
            int[,] chess = new int[8, 8];
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    chess[i, j] = 0;
                    //Console.Write(chess[0, 0].ToString());
                }
            }
            travel(3, 1, chess,0);

        }
        public static void travel(int i,int j,int[