Wildcard Matching dynamic programming