Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class csr3 {
- /**
- * csr3: given a n×m grid of connected points , starting from the top left
- * corner and ending at the buttom right corner, by moving only (down or
- * right) how many possible different paths? (e.g 2x2 output is 2 , 2x3
- * output is 3 , 3x3 output is 6) (Hint: at each point recursively call the
- * same function with the adjacent points).
- */
- static int n = 3, m = 3, s = 0;
- public static void solve(int i, int j) {
- if (i >= n || j >= m) {
- } else if (i == (n - 1) && j == (m - 1)) {
- s++;
- } else {
- solve(i + 1, j);
- solve(i, j + 1);
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- solve(0, 0);
- System.out.println(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement