class SumCombinations {
int count = 0;
public int getNumberOfOptions(int[] priceOfJeans, int[] priceOfShoes, int[] priceOfSkirts, int[] priceOfTops, int dollars) {
int[][] items = new int[][]{priceOfJeans, priceOfShoes, priceOfSkirts, priceOfTops};
backtrack(items, 0, dollars);
return count;
}
private void backtrack(int[][] items, int index, int rem) {
//base/exit condition
if(rem < 0){
return;
}
//process current candidate
if(index == items.length){
count++;
return;
}
//next candidates
int[] item = items[index];
for (int j : item) {
backtrack(items, index + 1, rem - j);
}}
public static void main(String[] args) {
SumCombinations sumCombinations = new SumCombinations();
int[] a = new int[]{2, 3};
int[] b = new int[]{4};
int[] c = new int[]{2, 3};
int[] d = new int[]{1, 2};
System.out.println(sumCombinations.getNumberOfOptions(a, b, c, d, 10));
}
}