problem Link : https://atcoder.jp/contests/dp/tasks/dp_f
solution Link: https://ide.codingblocks.com/s/314891
problem Link : https://atcoder.jp/contests/dp/tasks/dp_f
solution Link: https://ide.codingblocks.com/s/314891
Hello @amangoel987357, I have corrected your code so that you can understand what was the flaw with the logic. Although this code will give the TLE I just corrected what you were considering. So here I replaced initial state of dp as ‘-’ so as to represent our basic structure. Generally we don’t assign with the value that might come as an answer. May be you have noticed like in case of nos. generally we assign with -1 as we don’t expect it to be as the answer in any of the cases and here ‘’ empty string can come as an answer when either of the string is empty or there is no match. And next is I replaced the value of maxx to 0 rather than INT_MIN, this is because you are using out.size() and it is of type unsigned and while comparing nos. of type unsigned and long long , the long long no. gets converted into unsigned no. and as it becomes unsigned no. it takes a very large value hence giving us the wrong results.
Pls go through this code once for better understanding of the issues.
And now for correct ans you don’t need to consider the dp of strings , you need to consider the dp of integers and in that case you must consider the lengths of the string. And possibly one you fill the dp table then start traversing from the back in order to search for the string.
Pls, do a try in case there will be some confusion or issue I will surely help you out.
Thanks sir i understood what was the problem with my code. I will surely try to implement dp of integers and will let you know if i will face any problem.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.