Here you can find the source of sum_configurations(int[] elements, int sum)
static long sum_configurations(int[] elements, int sum)
//package com.java2s; //License from project: Apache License public class Main { /**/* w w w . j av a 2 s .c o m*/ * given a set of integers, returns the number of ways to make them add up * to sum, order dependent analogously, 'how many ways can i make change * with given coin denominations' */ static long sum_configurations(int[] elements, int sum) { long[] arr = new long[sum + 1]; arr[0] = 1; for (int i = 1; i < arr.length; ++i) { for (int j : elements) if (i - j >= 0) arr[i] += arr[i - j]; } return arr[sum]; } }