using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
palindromeSubStrs(String s)
{
int
[,] dp =
new
int
[s.Length, s.Length];
int
st, end, i, len;
Dictionary<String,
Boolean> m =
new
Dictionary<String,
Boolean>();
for
(i = 0; i < s.Length; i++)
{
dp[i,i] = 1;
if
(!m.ContainsKey(s.Substring(i, 1)))
m.Add(s.Substring(i, 1),
true
);
}
for
(i = 0; i < s.Length - 1; i++)
{
if
(s[i] == s[i + 1])
{
dp[i, i + 1] = 1;
if
(!m.ContainsKey(s.Substring(i, 2)))
m.Add(s.Substring(i, 2),
true
);
}
else
dp[i, i + 1] = 0;
}
for
(len = 3; len <= s.Length; len++)
{
for
(st = 0; st <= s.Length - len; st++)
{
end = st + len - 1;
if
(s[st] == s[end] &&
dp[st + 1, end - 1] == 1)
{
dp[st, end] = 1;
m.Add(s.Substring(st, end + 1-st),
true
);
}
else
dp[st, end] = 0;
}
}
return
m.Count;
}
public
static
void
Main(String[] args)
{
String s =
"abaaa"
;
Console.WriteLine(palindromeSubStrs(s));
}
}