Advertisement
Guest User

dorin

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. ublic static int numPaths (int[][] mat,
  2.              int x1, int y1, int x2, int y2)
  3.     {
  4.         return counterTracks(mat,x1,y1,x2,y2) ;
  5.                  
  6.     }
  7.    
  8.     private static int counterTracks (int[][] mat,
  9.              int x1, int y1, int x2, int y2)
  10.     {
  11.             if((x1<0 )||( y1<0 ) )
  12.             {
  13.                 return 0;
  14.             }
  15.            
  16.             if((x1 == mat.length )|| (y1 == mat.length))
  17.             {
  18.                 return 0;
  19.             }
  20.             if((x1==x2) || (y1==y2))
  21.             {
  22.                 return 1;
  23.             }
  24.              if(x1>y1)
  25.              {
  26.                  return 0;
  27.              }
  28.              
  29.              if(mat[x1][y1] == -1)
  30.              {
  31.                  return 0;
  32.              }
  33.              
  34.              int counter = mat[x1][y1];
  35.             mat[x1][y1]=-1;
  36.  
  37.             int sum= counterTracks(mat,x1-1,y1,x2,y2) + counterTracks(mat,x1,y1-1,x2,y2)
  38.             +counterTracks(mat,x1+1,y1,x2,y2) + counterTracks(mat,x1,y1+1,x2,y2);
  39.            
  40.             mat[x1][y1]= counter;
  41.             return sum;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement