-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c13b83
commit ca6c8b8
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,4 @@ http://www.spoj.com/users/raj94/ | |
68) MIXTURES | ||
69) GCD2 | ||
70) ANARC09A | ||
71) AIBOHP |