Advertisement
Infernale

Combination

Nov 23rd, 2018
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main{
  4.     private static int count(int[] in, int m, int n){
  5.         if(n==0){
  6.             return 1;
  7.         }
  8.         if(n<0){
  9.             return 0;
  10.         }
  11.         if(m<=0 && n>=1){
  12.             return 0;
  13.         }
  14.         return count(in, m-1, n) + count(in, m, n-in[m-1]);
  15.     }
  16.     public static void main(String[]args){
  17.         int[] arr = {1, 2, 3, 4, 5};
  18.         System.out.println(count(arr, 5, 5));
  19.  
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement