이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <string>
bool isPalindrome(const std::string& str) {
int start = 0;
int end = str.size() - 1;
while (start < end) {
if (str[start] != str[end]) {
return false;
}
start++;
end--;
}
return true;
}
int maxPalindromicPartitions(const std::string& s) {
int n = s.size();
if (n == 0) return 0;
std::vector<std::vector<int>> dp(n, std::vector<int>(n, 0));
for (int i = 0; i < n; ++i)
dp[i][i] = 1;
for (int cl=2; cl<=n; ++cl)
for (int i=0; i<n-cl+1; ++i){
int j = i+cl-1;
if (isPalindrome(s.substr(i, cl)) && cl == j-i+1)
dp[i][j] = 1;
else
dp[i][j] = std::max(dp[i][j-1], dp[i+1][j]);
}
return dp[0][n-1];
}
int main() {
int t;
std::cin >> t;
while(t--) {
std::string s;
std::cin >> s;
std::cout << maxPalindromicPartitions(s) << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |