比较花时间的想法,经过测试,只有一个不超时,蛮记录一下
思路:
请在此输入您的代码
#根据例子推出来有两种可能
#1 38
#2 19
#反推比较合理的是这一种
#bba & aabcaba
#不重复原则下
#正回文串 2种 ( a,b)
#非正回文串=所有字串-正会问串
import os
import sys
import re
# 请在此输入您的代码
n=int(input())
s=input()
score=0
def reverse(s):
return s[::-1]
#计算子字符串个数
def cnt_all(s):
lst=[]
n=len(s)
count=0
#字串长度
for i in range(1,n+1):
for j in range(n-i+1):
ss=s[j:j+i]
if ss not in lst:
lst.append(ss)
count=count+1
return count
#计算正回文
def cnt(s):
n=len(s)
t=1
lst=[]
count=0
while(t<=n):
for i in range(n-t+1):
if s[i:i+t] not in lst:
lo=i+(t-1)/2
up=i+(t-1)/2+1
if t==1:
lst.append(s[i])
count=count+1
elif s[i:lo]==reverse(s[up:i+t]):
lst.append(s[i:i+t])
count=count+1
t=t+2
return count
#前一段的个数
for i in range(1,n):
A=cnt(s[:i])
B=cnt_all(s[i:])-cnt(s[i:])
temp=int(A*B)
if temp>score:
score=temp
print(score)
根据该题的标签做应该会快吧,不知道咋做