private static int TargetSumUsingSubsetOfElementsUtils(int n, int v, Node root) { n = n - v; if (n < 0) { return(0); } else if (n == 0) { return(1); } //if(dp[n] != 0 ) //{ // return dp[n]; //} return(dp[n] = TargetSumUsingSubsetOfElementsUtils(n, 1, TernaryTree.Construct(root, "left", n, 1)) + TargetSumUsingSubsetOfElementsUtils(n, 3, TernaryTree.Construct(root, "mid", n, 3)) + TargetSumUsingSubsetOfElementsUtils(n, 5, TernaryTree.Construct(root, "right", n, 5))); }