100分以下的请注意!
查看原帖
100分以下的请注意!
1124373
LengMeng楼主2024/1/26 00:36

看看你们代码马的跳跃坐标数组的下标是否超出

判断一下数组下标是否小于0 输入的正整数 可能是0或1

using System;
public class CrossRiver
{
    public static bool[,] horse = new bool[25, 25];
    public static ulong[,] dp = new ulong[25, 25];
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]), m = int.Parse(input[1]);
        int x = int.Parse(input[2]), y = int.Parse(input[3]);
        dp[1, 1] = 1;
        n++;m++;x++;y++;
        horse[x,y] = true;
        if(x - 2 >= 0)
        {
            horse[x - 2, y + 1] = true;
            horse[x - 2, y - 1] = true;
        }
        if(y - 2 >= 0)
        {
            horse[x - 1, y - 2] = true;
            horse[x + 1, y - 2] = true;
        }
        horse[x+2, y-1] = true;
        horse[x+2, y+1] = true;
        horse[x-1, y+2] = true;
        horse[x+1, y+2] = true;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if(i == 1 & j == 1)
                    continue;
                if (horse[i, j])
                {
                    dp[i, j] = 0;
                    continue;
                }

                if (!horse[i,j])
                {
                    dp[i,j] = dp[i-1,j] + dp[i,j-1];
                }
            }
        }
        Console.WriteLine(dp[n,m]);
        Console.ReadLine();
    }
}
2024/1/26 00:36
加载中...