Advertisement
_no0B

Untitled

Dec 11th, 2021
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. string dir;
  2.  
  3. int dxx[] = {1, 0, , 0, -1};
  4. int dyy[] = {0, -1, 1, 0};
  5.  
  6. string dfs(int row , int col , int k)
  7. {
  8.  
  9.     if(k == 0) return "";
  10.  
  11.     for(int i = 0 ; i < 4 ; i++){
  12.         int x = row + dxx[i] , y = col + dyy[i];
  13.         if(dis[x][y] < k){
  14.             string ans = dfs(x, y , k-1);
  15.             if(ans == "IMPOSSIBLE") return ans;
  16.             return dir[i] + ans;
  17.         }
  18.     }
  19.     return "IMPOSSIBLE";
  20. }
  21.  
  22.  
  23.  
  24. int main()
  25. {
  26.     /// problem: https://codeforces.com/problemset/problem/769/C
  27.  
  28.     dir = "DLRU";
  29.  
  30.     for(int i = 0 ; i < n ; i++){
  31.         for(int j = 0 ; j < m ; j++){
  32.             if(str[i][j] == 'X'){
  33.                 bfs(i , j);
  34.                 cout<<dfs(i , j , k)<<endl;
  35.                 return 0;
  36.             }
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement