/
5-dp.go
47 lines (45 loc) · 2.1 KB
/
5-dp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
//func longestPalindrome(s string) string {
//
//}
//#include <iostream>
//#include <algorithm>
//
//using namespace std;
//bool dp[1000][1000];
//
//string longestPalindrome(string s)
//{
// int max = -1, a = 0, b = 1, j = 0, size = s.size();
// for (int l = 0; l < size; ++l)
// {
// for (int i = 0; i + l < size; ++i)
// {
// j = i + l;
// if (l == 0)
// dp[i][j] = true;
// else if (l == 1)
// dp[i][j] = s[i] == s[j];
// else
// dp[i][j] = s[i] == s[j] && dp[i + 1][j - 1];
// if (dp[i][j] && max < l + 1)
// {
// max = l + 1;
// a = i;
// b = l + 1;
// }
// }
// }
// return s.substr(a, b);
//}
//
//int main()
//{
// // cout << longestPalindrome("babad") << endl;
// // cout << longestPalindrome("avvccvvas") << endl;
// // cout << longestPalindrome("vbfddfawee") << endl;
// cout << longestPalindrome("aaabaaaa") << endl;
// cout << longestPalindrome(
// "civilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")
// << endl;
//}