机器人的运动路径
int getnum(int x)
{
int sum = 0;
while (x)
{
sum += x % 10;
x /= 10;
}
return sum;
}
void dfs(int threshold, int i, int j, int rows, int cols, int &sum, vector<int> &flag)
{
if (i < 0 || i >= rows || j < 0 || j >= cols) return;
if (flag[i*cols + j] == 1) return;
if ((getnum(i) + getnum(j)) <= threshold)
{
sum++;
flag[i*cols + j] = 1;
dfs(threshold, i - 1, j, rows, cols, sum, flag);
dfs(threshold, i + 1, j, rows, cols, sum, flag);
dfs(threshold, i, j - 1, rows, cols, sum, flag);
dfs(threshold, i, j + 1, rows, cols, sum, flag);
}
}
int movingCount(int threshold, int rows, int cols)
{
vector<int> flag(rows*cols, 0);
int max = 0;
dfs(threshold, 0, 0, rows, cols, max, flag);
return max;
}
```矩阵中的路径
class Solution {
public:
bool path(char* matrix,int i ,int j,int rows,int cols,ch