Wildcard Pattern Matching problem

What size of DP array should I take? I think that is creating problem. Is there any flaw in logic ?