Advertisement
leonardo_aly7

csr3

Jan 30th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. public class csr3 {
  2.  
  3.     /**
  4.      * csr3: given a n×m grid of connected points , starting from the top left
  5.      * corner and ending at the buttom right corner, by moving only (down or
  6.      * right) how many possible different paths? (e.g 2x2 output is 2 , 2x3
  7.      * output is 3 , 3x3 output is 6) (Hint: at each point recursively call the
  8.      * same function with the adjacent points).
  9.      */
  10.  
  11.     static int n = 3, m = 3, s = 0;
  12.  
  13.     public static void solve(int i, int j) {
  14.  
  15.         if (i >= n || j >= m) {
  16.         } else if (i == (n - 1) && j == (m - 1)) {
  17.             s++;
  18.         } else {
  19.             solve(i + 1, j);
  20.             solve(i, j + 1);
  21.         }
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         // TODO Auto-generated method stub
  26.         solve(0, 0);
  27.         System.out.println(s);
  28.  
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement