problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
leetcode::knight_probability_in_chessboard::Solution类 参考

#include <leetcode.h>

Public 成员函数

double knightProbability (int n, int k, int row, int column)
 

Private 属性

unordered_map< status, double, status_hash, status_equalum = unordered_map<status, double, status_hash, status_equal>()
 

详细描述

在文件 leetcode.h1184 行定义.

成员函数说明

◆ knightProbability()

double leetcode::knight_probability_in_chessboard::Solution::knightProbability ( int  n,
int  k,
int  row,
int  column 
)

在文件 leetcode.cpp3030 行定义.

3030 {
3031 if(k == 0) {
3032 return 1;
3033 }
3034 const auto s = status(k, row, column);
3035 if(um.count(s) == 1) {
3036 return um[s];
3037 }
3038 int off = 0;
3039 pair<int, int> nexts[8] = {make_pair(row - 2, column - 1),
3040 make_pair(row - 2, column + 1),
3041 make_pair(row + 2, column - 1),
3042 make_pair(row + 2, column + 1),
3043 make_pair(row - 1, column - 2),
3044 make_pair(row - 1, column + 2),
3045 make_pair(row + 1, column - 2),
3046 make_pair(row + 1, column + 2)};
3047 double sum = 0;
3048 for(auto [next_x, next_y]: nexts) {
3049 if(0 <= next_x && next_x < n && 0 <= next_y && next_y < n) {
3050 sum += knightProbability(n, k - 1, next_x, next_y);
3051 }
3052 }
3053 const double ans = sum / 8;
3054 um[s] = ans;
3055 return ans;
3056 }
unordered_map< status, double, status_hash, status_equal > um
Definition: leetcode.h:1185
double knightProbability(int n, int k, int row, int column)
Definition: leetcode.cpp:3030

引用了 knightProbability() , 以及 um.

被这些函数引用 knightProbability().

类成员变量说明

◆ um

unordered_map<status, double, status_hash, status_equal> leetcode::knight_probability_in_chessboard::Solution::um = unordered_map<status, double, status_hash, status_equal>()
private

在文件 leetcode.h1185 行定义.

被这些函数引用 knightProbability().


该类的文档由以下文件生成: