Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main{
- private static int count(int[] in, int m, int n){
- if(n==0){
- return 1;
- }
- if(n<0){
- return 0;
- }
- if(m<=0 && n>=1){
- return 0;
- }
- return count(in, m-1, n) + count(in, m, n-in[m-1]);
- }
- public static void main(String[]args){
- int[] arr = {1, 2, 3, 4, 5};
- System.out.println(count(arr, 5, 5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement