fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. { public static void flood(int n , int m ,int i ,int j ,int [][] mat , boolean [][] vis,String psf){
  10. if(i>=n || j >=m || i <0 || j<0 || vis[i][j] == true|| mat[i][j] == 1){
  11. return;
  12. }
  13.  
  14. if(i == m-1 && j == n-1){
  15. System.out.println(psf);
  16. return;
  17. }
  18. vis[i][j] = true;
  19. flood(n,m,i-1,j,mat,vis,psf+"t");
  20. flood(n,m,i,j-1,mat,vis,psf + "l");
  21. flood(n,m,i+1,j,mat,vis,psf+"d");
  22. flood(n,m,i,j+1,mat,vis,psf+"r");
  23.  
  24. vis[i][j] = false;
  25. }
  26. public static void main (String[] args) throws java.lang.Exception
  27. {
  28. int mat[][] = {{0,0,1},{0,1,1},{0,0,0}};
  29. int n = mat.length;
  30. int m = mat[0].length;
  31.  
  32. boolean[][] vis = new boolean[n][m];
  33. flood(n,m,0,0,mat,vis,"");
  34. }
  35. }
Success #stdin #stdout 0.1s 57364KB
stdin
Standard input is empty
stdout
ddrr