虚拟两个点,一个从左上角开始走,一个从右下角开始走,定义dp[i][j][k]表示走了i步后,第一个点横向走了j步,第二个点横向走了k步后形成的回文方法种数. 转移方程显然可得,然后滚动数组搞一搞. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> #…
Description Viruses are usually bad for your health. How about fighting them with... other viruses? In this problem, you need to find out how to synthesize such good viruses. We have prepared for you a set of strings of the letters A, G, T and C. T…
题目 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 题解 dp.先初始化长度为1和长度为2的串.再依次算长度为3,4,5.... 当找到回文串时,若长度比当前记录的回文串长度大,则更新起始位置和最大长度,最终用substring返回子串. 时间复杂度O(n2).空间复杂度O(n2). todo 还可以用中心扩展法.和马拉车法,待学习. 代码 class Solution { public String longestPalindrome(String…
Palindrome Function Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 559 Accepted Submission(s): 299 Problem Description As we all know,a palindrome number is the number which reads the same…