This is a continuation of this problem. Find all combinations that sum up to a specific number
Think of following values.
T = Target // The value to target. eg 100
I = Items // Number of items that makes T. eg 5
Now Not just like previous question, I want the numbers to be increased by an interval step (instead of $1$) like $2$, $5$, $10$, etc. The step value is $S$ (eg: $2$, $5$, $10$).
Also $H_i$ will tell what is the maximum value specific I will reach and $L_i$ will tell what is the lowest value specific I will start with.
Eg:
$T = 100$, $I = 3$, $S = 2$
$L_1 = 10$, $L_2 = 20$, $L_3 = 0$
$H_1 = 100$, $H_2 = 80$, $H_3 = 80$
If above are the value, all combination will look like below
010, 020, 070
010, 022, 068 ;Always Increasing / Decrease by 2 since S = 2
010, 024, 066
010, 026, 064
..... ;After many combinations
010, 080, 000
012, 020, 068
012, 022, 066
.....
.....
080, 018, 002
080, 020, 000
Even though $H_1=100$, $I_1$ cannot reach $100$ since $L_2=20$.
What is the formula to find number if combination we can arrive with if $T$, $I$, $S$, $H_i$ and $L_i$ are given? Even solution as programming is enough.
Based on additional information given in the comments above, the problem can be stated as:
Define $T' = \dfrac{1}{S} \left( T - \sum\limits_{k = 1}^I L_k \right)$, $M_k = \dfrac{1}{S} (H_k - L_k)$, $y_k = \dfrac{1}{S} (x_k - L_k)$, then the problem is equivalent to find the number of integer solutions to$$ \sum_{k = 1}^I y_k = T' $$ with constraints$$ 0 \leqslant y_k \leqslant M_k. \quad k = 1, \cdots, I $$
Now define $f(0, 0) = 1$, $f(0, m) = 0\ (m ≠ 0)$, and $f(n, m)\ (1 \leqslant n \leqslant I)$ as the number of integer solutions to$$ \sum_{k = 1}^n y_k = m $$ with constraints$$ 0 \leqslant y_k \leqslant M_k. \quad k = 1, \cdots, n $$ For fixed $n$, since $0 \leqslant y_n \leqslant M_n$, then$$ f(n, m) = \sum_{k = 0}^{M_n} f(n - 1, m - k). $$ Note that the case where $n = 1$ is included. Further define$$ g(n, m) = \begin{cases} \sum\limits_{k = 0}^m f(n, k); & m \geqslant 0\\ 0; & m < 0 \end{cases}, $$ then$$ \begin{cases} f(n, m) = g(n - 1, m) - g(n - 1, m - M_n - 1)\\ g(n, m) = g(n, m - 1) + f(n, m) \end{cases}, \quad (n \geqslant 1,\ m \geqslant 0) $$ or$$ \begin{cases} f(n, m) = g(n - 1, m)\ (0 \leqslant m \leqslant M_n)\\ f(n, m) = g(n - 1, m) - g(n - 1, m - M_n - 1)\ (m > M_n)\\ g(n, 0) = 1\\ g(n, m) = g(n, m - 1) + f(n, m)\ (m \geqslant 1) \end{cases} $$
The code is showed below (with some optimization).
The time complexity is approximately $O(TIS^{-1})$.