-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
Hey, this repo you have made has helped me a lot, because I get the logic but when it comes to coding it, it sometimes feels difficult, so thank you for making this amazing repo 🙌🙌.
and in this too -> https://github.com/shubhamchemate003/Dynamic-Programming-Questions-by-Aditya-Verma/blob/main/pallindrome_partitioning_memoized_optimization.cpp
just pass the string with reference(&) in both the function ( isPallindrome and Solve) and it will not give TLE .
Just wanted to help, because I think there would be a lot of people like me who are getting help through this repo.
code :
bool isPallindrome(string &X, int i, int j) {
while (i <= j) {
if (X[i] != X[j])
return false;
i++, j--;
}
return true;
}
int Solve(string &X, int i, int j) {
if (i >= j || isPallindrome(X, i, j)) {
t[i][j] = 0;
return 0;
}
if (t[i][j] != -1)
return t[i][j];
int ans = INT_MAX;
for (int k = i; k < j; k++) {
int temp_ans = Solve(X, i, k) + Solve(X, k + 1, j) + 1;
ans = min(ans, temp_ans);
}
return t[i][j] = ans;
}
Metadata
Metadata
Assignees
Labels
No labels