Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem 15-2: More Efficient Algorithm #482

Open
cpchenpi opened this issue Aug 25, 2023 · 0 comments
Open

Problem 15-2: More Efficient Algorithm #482

cpchenpi opened this issue Aug 25, 2023 · 0 comments

Comments

@cpchenpi
Copy link

There exists an $O(n^2)$ algorithm for problem 15-2.
Instead of enumerate all midpoint and solve LCS problem, we can use an interval dp method. Define dp[i, j] the answer for substring s[i..j], we can extend it (and plus one) to dp[i-1, j+1] if s[i-1]=s[j+1]. Also extend it to dp[i, j+1] and dp[i-1, j].
Actually it's just leetcode problem 516.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant