1

Getting TLE on DP problem

 2 years ago
source link: http://codeforces.com/blog/entry/96703
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I don't know why ii am getting TLE on this problem.

My approach: The state is that for each i and j I have 3 conditions. The first one is to increment i and the second is to decrement j and the 2 conditions I add one to them which is the cost. The third condition has 2 conditions if s[i] = s[j] then I do i+1 and j-1 without adding one and else I do the same but with the addition of one. So shouldn't the time complexity of my code be (n^2 * T) which is the size of my DP array * the number of test cases and the final time should be 1e7 which should pass, please correct me if I am wrong.

Code:https://ideone.com/HfNl6J

Problem:https://vjudge.net/problem/UVA-10739/origin


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK