Need some help in this problem. I'm doing this problem using Tries + DFS + DP. My dp[i] basically stores number of different phrases from ith index to n-1th index. So the final result would be stored in dp[0]. My approach seems to be correct i guess but still i'm getting wrong answer. Here is the link to the problem -> http://www.spoj.com/problems/MORSE/ Here is the link to my code -> http://ideone.com/qmIMKm