Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class CountPaths {
- public static void main (String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int t = Integer.parseInt(br.readLine().trim());
- while(t-->0){
- String inputLine[] = br.readLine().trim().split(" ");
- int M = Integer.parseInt(inputLine[0]);
- int N = Integer.parseInt(inputLine[1]);
- Solution ob = new Solution();
- System.out.println(ob.numberOfPaths(M, N));
- }
- }
- }
- // } Driver Code Ends
- class Solution{
- long numberOfPaths(int M, int N) {
- if ((M == 1) || (N == 1)) {
- return 1;
- }
- return numberOfPaths(M - 1, N) + numberOfPaths(M, N - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement