Created
July 16, 2017 15:33
-
-
Save TheNilesh/3e3c970f32bbbbafe98f2406dce1e014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int count = scanner.nextInt(); | |
for (int i = 0; i < count; i++) { | |
int N = scanner.nextInt(); /*Number of 0's*/ | |
int M = scanner.nextInt(); /*Number of 1's*/ | |
System.out.println( nCr(N + M - 1, N) ); | |
} | |
} | |
public static int nCr(int n, int r) { | |
return factorial(n) / (factorial(n - r) * factorial(r)); | |
} | |
public static int factorial(int n) { | |
if (n == 1 || n == 0) { | |
return 1; | |
} | |
return n * factorial(n - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment