The overal idea of the sub-problem sounds good.
I've noticed a few issues:
What is k supposed to represent?
$j$ represents the number of machines unsold at the end of month $i$. This can't be negative as you cannot have a negative number of machines unsold, which means you sold more than what you produced!
You said you start with $MinCost(n,0)$ so you start with $j=0$, but then you need to compute $MinCost(n-1,0-k)$ and you wrote that $1 \leq k$, which leaves to negative $j$!. There seem to be an issue here.
I think your idea was that $k$ was the net difference of machines unsold on day $i$, which makes it hard to reason about.
So let's define $k$ as the number of unsold machines at the beginning of month $i$ (= number of unsold at the end of month $i-1$).
What is $c(k,j,i)$?
You should have enough data to compute the costs yourself. 603
By the new definition of $k$, $c(k,j,i)= c \cdot (j-k + d_i - m)$. This is because you had $k$ machine at the beginning of month $i$, you have $j$ machines at the end of that month and you sold $d_i$ machines, so you produced $j-k + d_i$ machines that month. You can produce $m$ machines without any additional cost so the remaining number of machine costs $c$ dollars per machine.
Please note that this value cannot be negative, as you can't get back the costs if you have to build less than $m$ machines. So $c(k,j,i)= max(0, c \cdot (j-k + d_i - m))$.
This brings us to
$\quad MC(i,j) = \min{MC(i-1,k) + max(0, c \cdot (j-k + d_i - m)) + h(j) \mid 0 \le k \le D }$
With $MC(0, j) = \begin{cases} 0 & \quad \text{if } i = 0\ + \infty & \quad \text{if } i \neq 0 \end{cases}$
Because you can't have machines in stock before the first day.
We could make some optimisation on the max value of $k$ but it's a bit hard to compute and won't improve the asymptotic complexity.
I believe this should be enough to write the algorithm. 143