Skip to content

Commit

Permalink
AIBOHP haha palindrome not LCS
Browse files Browse the repository at this point in the history
  • Loading branch information
ramjeetsaran committed Sep 27, 2015
1 parent 1c13b83 commit ca6c8b8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions AIBOHP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//DATE: 27/09/2015
//Author: Ramjeet Saran
//http://www.spoj.com/problems/AIBOHP/

#include <bits/stdc++.h>

#define gc getchar_unlocked
#define pc putchar_unlocked
# define MAX(a,b) a>b ? a : b;
# define MIN(a,b) a<b ? a : b;
# define lli long long int
# define ull unsigned long long int

using namespace std;

static unsigned short int DP[6200][6200];

void fastwrite(int inp){
int a=(inp<0)?-inp:inp;
char snum[20];
int i=0;
do
{
snum[i++]=a%10+48;
a=a/10;
}while(a!=0);
if(inp<0)
snum[i++]='-';
i--;
while(i>=0)
pc(snum[i--]);
pc('\n');
}

int compute(string IN){

int len = IN.length();
for(int i = 0; i <= len; i++) {
for(int j = 0; j <= len; j++) {
if (i == 0 || j == 0)
DP[i][j] = 0;
else {
if(IN[i - 1] == IN[len - j])
DP[i][j] = DP[i - 1][j - 1] + 1;
else
DP[i][j] = MAX(DP[i][j - 1], DP[i - 1][j]);
}
//cout<<DP[i][j]<<" ";
}
//cout<<endl;
}

return len - DP[len][len];
}

int main(){
int T;
string B;
cin>>T;
while(T--){
cin>>B;
fastwrite(compute(B));
}
}
1 change: 1 addition & 0 deletions Readme
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ http://www.spoj.com/users/raj94/
68) MIXTURES
69) GCD2
70) ANARC09A
71) AIBOHP

0 comments on commit ca6c8b8

Please sign in to comment.