首页 > 解决方案 > 动态规划 - 在棋盘中使用 3 维向量来表示骑士概率。获取错误代码 (0xC0000005)> 谁能看到有什么问题?

问题描述

float knightStay(int k, int r, int c, int n, vector<vector<vector>> &dp) { //基本情况 if (r<0||r>=n||c<0||c>= n) {

        return 0;}

// no more moves to make and we've by passed out of bounds case, meaning we are in the board
if(k==0) {
        return 1;
}
else {
        float sumProbability=0;
        if(dp[k][r][c] == -1) {

            for(auto i=directions.begin();i<directions.end();i++) {
                pair<int, int> currentDirection = *i;
                sumProbability += knightStay(k-1, r+currentDirection.first, c+currentDirection.second, n, dp);
            }
            dp[k][r][c] = sumProbability/8;
            return dp[k][r][c];

        } else {
            return dp[k][r][c];
        }

}

}

标签: vector

解决方案


推荐阅读