leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0576.cpp (794B)


0 class Solution { 1 static const int MOD = 1E9 + 7; 2 static int dp[51][51][51]; 3 4 public: 5 Solution() { memset(dp, 0xFF, sizeof(dp)); } 6 int findPaths(const int m, const int n, const int moves, const int row, const int col) const { 7 if (!moves) return 0; 8 if (dp[moves][row][col] != -1) return dp[moves][row][col]; 9 int res = 0; 10 11 static int offset[] = {-1, 0, 1, 0, -1}; 12 for (int k = 0; k < 4; k++) { 13 const int x = row + offset[k]; 14 const int y = col + offset[k + 1]; 15 if (x < 0 || y < 0 || x >= m || y >= n) 16 res++; 17 else 18 res = (res + findPaths(m, n, moves - 1, x, y)) % MOD; 19 } 20 21 return dp[moves][row][col] = res; 22 } 23 }; 24 25 int Solution::dp[51][51][51];