Coding Problem Link i have coded the brute-force recursion without any DP.
public class coinChangeCombination {
public static void main(String[] args){
int[] coins = {2, 3, 5, 6};
int target = 7;
System.out.println(coinRecursive(0, target, coins, 0));
}
//basic recursion
public static int coinRecursive(int current, int target, int[] coins, int index){
if(current > target) return 0;
if(current == target) return 1;
int count = 0;
for(int i = index; i < coins.length; i++){
int res = coinRecursive(current+coins[i], target, coins, i);
count += res;
}
return count;
}
}
Now since two variables are getting changed in recursion, we will need a 2-d array to store the intermediate results but what does each cell of the 2-d array represent? Like in Fibonacci DP when we take a 1-d array, each cell represents the Fibonacci of that index, likewise what does our 2-d array in this question represent? i am unable to think the meaning behind it, whats the intuition?