- #include <bits/stdc++.h>
- using namespace std;
- bool pal[1001][1001];
- int main()
- {
- int test, cs = 1;
- scanf("%d", &test);
- while( test-- ){
- int l;
- string s;
- cin>>s;
- l = s.length();
- for(int i = 0; i <l; i++){
- pal[i][i] = true;
- }
- for(int len = 2; len<= l ; len++){
- for(int i = 0; i <l-len+1; i++){
- int j = i+len-1;
- if(len == 2){
- pal[i][j] = (s[i] == s[j]);
- }
- else{
- pal[i][j] = pal[i+1][j-1] && (s[i] == s[j]);
- }
- }
- }
- int c[l];
- for (int i=0; i<l; i++)
- {
- if (pal[0][i] == true)
- c[i] = 0;
- else
- {
- c[i] = INT_MAX;
- for(int j=0;j<i;j++)
- {
- if(pal[j+1][i] == true && 1+c[j]<c[i])
- c[i]=1+c[j];
- }
- }
- }
- printf("Case %d: %d\n", cs++, c[l-1] + 1);
- }
- return 0;
- }
Thursday 27 July 2017
Lightoj 1044 - Palindrome Partitioning
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment