<script>
function
LPCRec(curr_str, count, leng, s){
if
(!curr_str)
return
0
if
(curr_str.length <= 1){
if
(count != 0 && s.length - leng <= 1)
return
(count + 1)
else
return
1
}
let n = curr_str.length
for
(let i=0;i<Math.floor(n/2);i++){
if
(curr_str.substring(0,i+1) == curr_str.substring(n-1-i,n))
return
LPCRec(curr_str.substring(i + 1,n - 1 - i), count + 2, leng + (i + 1) * 2, s)
}
return
count + 1
}
function
LPC(s){
return
LPCRec(s, 0, 0, s)
}
document.write(
"V :"
, LPC(
"V"
),
"</br>"
)
document.write(
"VOLVO :"
, LPC(
"VOLVO"
),
"</br>"
)
document.write(
"VOLVOV :"
, LPC(
"VOLVOV"
),
"</br>"
)
document.write(
"ghiabcdefhelloadamhelloabcdefghi :"
,
LPC(
"ghiabcdefhelloadamhelloabcdefghi"
),
"</br>"
)
document.write(
"ghiabcdefhelloadamhelloabcdefghik :"
,
LPC(
"ghiabcdefhelloadamhelloabcdefghik"
),
"</br>"
)
document.write(
"antaprezatepzapreanta :"
,
LPC(
"antaprezatepzapreanta"
),
"</br>"
)
</script>