1 int dfs(int m, int n, int k, int i, int j, int *visited) 2 { 3 if(i < 0 || i == m || j < 0 || j == n || visited[i*n + j] == 1 || i%10+i/10+j%10+j/10 > k) 4 { 5 return 0; 6 } 7 visited[i*n + j] = 1; 8 return dfs(m,n,k,i+1,j,visited) + dfs(m,n,k,i,j+1,visited) + 1; 9 } 10 11 int movingCount(int m, int n, int k) 12 { 13 int visited[m * n]; 14 memset(visited,0,m*n*sizeof(int)); 15 int ans = dfs(m,n,k,0,0,(int *)visited); 16 return ans; 17 }
机器人的运动范围(dfs)(leetcode 4.8 每日打卡)
原文:https://www.cnblogs.com/ZhengLijie/p/12661904.html