// Author: Huahua
bool isPalindrome(const string& s) {
const int n = s.length();
for (int i = 0; i < n / 2; ++i)
if (s[i] != s[n - 1 - i]) return false;
return true;
}
class Solution {
public:
vector<vector<string>> partition(string s) {
int n = s.length();
vector<vector<vector<string>>> dp(n + 1);
for (int len = 1; len <= n; ++len) {
for (int i = 0; i < len; ++i) {
string right = s.substr(i, len - i);
if (!isPalindrome(right)) continue;
if (i == 0) dp[len].push_back({right});
for (const auto& p : dp[i]) {
dp[len].push_back(p);
dp[len].back().push_back(right);
}
}
}
return dp[n];
}
};