|
分類:[C#]
using System;
class CrazyBot { double[] prob = new double[4]; bool[,] grid = new bool[100,100]; int[] mx = new int[4]{1,-1,0,0}; int[] my = new int[4] {0,0,1,-1};
public double getprobability(int n, int west,int east, int north, int south) {
prob[0] = east / 100; prob[1] = west / 100; prob[2] = north / 100; prob[3] = south / 100;
return dfs(50, 50, n); }
public double dfs(int x, int y, int n) { if (n == 0) return 1; if (grid[x, y]) return 0;
double ret = 0; grid[x, y] = true;
for (int i = 0; i < 4; i++) { ret += dfs(x + mx[i], y + my[i], n - 1) * prob[i];
} grid[x, y] = false;
return ret; } }
class DO { public static void Main() { CrazyBot cb = new CrazyBot(); Console.WriteLine("" + cb.getprobability(10, 25, 25, 25, 25)); } } 上のようなコードをかいて試しに値を代入してみたのですが結果が0になってしまいます。 何故そうなるのか教えてください
|