Advertisement
bogolyubskiyalexey

MathBase task G

Aug 17th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.math.BigInteger;
  5.  
  6.  
  7. public class Main {
  8.    
  9.     public static final int BASE = 1000 * 1000 * 1000 + 7;
  10.     public static final int MAX_N = 3000 + 10;
  11.  
  12.     public static int[][] T = new int[MAX_N][MAX_N];
  13.  
  14.     public static int C(int n, int k) {
  15.         if (n == k || k == 0) {
  16.             return 1;
  17.         }
  18.         if (T[n][k] == 0) {
  19.             T[n][k] = (C(n-1, k-1) + C(n-1, k)) % BASE;
  20.         }
  21.         return T[n][k];
  22.     }
  23.    
  24.    
  25.     public static void main(String []args) {
  26.        
  27.         Scanner in  = new Scanner(System.in);
  28.         int T = in.nextInt();
  29.         for (int t = 0, N, L; t < T; ++t) {
  30.             N = in.nextInt();
  31.             L = in.nextInt();
  32.             System.out.println(C(N - 1, L - 1));
  33.         }
  34.        
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement