0803阿里笔试第二题这样做对不对?
T='bbeeae' m=len(T) res=1 dp=[[0]*(m+1) for _ in range(m+1)] for i in range(m,0,-1) : c=False d=False e=False f=False for j in range(i,m+1): if T[j-1]=='e': dp[i][j] = dp[i][j-1]+1 e=True if T[j-1]=='f': dp[i][j] = dp[i][j-1]+1 f=True if T[j-1]=='a': if c or e: dp[i][j]=dp[i][j-1] else: dp[i][j]=dp[i][j-1]+1 if T[j-1]=='b': if d or f: dp[i][j]=dp[i][j-1] else: dp[i][j]=dp[i][j-1]+1 if T[j-1]=='c': if e: dp[i][j]=dp[i][j-1] else: dp[i][j]=dp[i][j-1]+1 c=True if T[j-1]=='d': if f: dp[i][j]=dp[i][j-1] else: dp[i][j]=dp[i][j-1]+1 d=True if dp[i][j]>res: res=dp[i][j] print (res)
#阿里巴巴##笔试题目#