Path of exact cost k in DAG

struggling with this question from an exam:

input:

DAG G=(V,E). each edge $$e_i$$ has weight $$w_i\in \text{{0,1,2,3}}$$

Two vertices : s,t

Number: k

output:

A path from s to t with total cost k (if exists)

• What have you tried? Where did you get stuck? – dkaeae Jul 15 '19 at 13:16
• tried to transform the problem into exact length of k and didn't really know how to continue. – qksr55789 Jul 16 '19 at 7:53

Now, go through all vertexes in order. For each vertex $$v$$, keep all the possible costs of a path from $$s$$ to $$v$$; there will be no more than $$3V$$ distinct costs. For each edge $$e(v,u)$$, add to $$u$$ the costs of $$v$$ + the weight of $$e$$.