括號配對 區間DP 回文子串

2021-10-24 13:21:44 字數 1178 閱讀 3037

遞迴定義一組字元匹配模式

增加幾個字元滿足這個匹配。

新增多少個字元,可以轉化為n-「回文子串」,這裡的回文子串需要重新定義

aaaabbbb:a符合定義,b也符合定義的話:最長子串,我們列舉中間端點取最大值。

abba:這種情況,我們判斷【l, r】 match(l,r)是不是匹配,匹配的話f(l+1,r-1)+2

#pragma comment(linker, "/stack:1024000000,1024000000")

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace std;

typedef

long

long ll;

typedef

unsigned

long

long ull;

#define mst(s,_s) memset(s, _s, sizeof(s))

const

double pi =

acos(-

1.0)

;const

double eps =

1e-6

;const

int inf =

0x3f3f3f3f

;const

int n =

1e3+

100;

int t,n,m;

char str[n]

;int f[n]

[n];

bool

match

(char a,

char b)

intmain()

}}cout<

[n]<

return0;

}

最長回文子串(區間dp)

輸入乙個字串str,輸出str裡最長回文子串的長度。回文串 指aba abba cccbccc aaaa這種左右對稱的字串。串的子串 乙個串的子串指此 字元 串中連續的一部分字元構成的子 字元 串 例如 abc 這個串的子串 空串 a b c ab bc abc 輸入str str的長度 1000 ...

合併回文子串 區間dp

題目描述 輸入兩個字串a和b,合併成乙個串c,屬於a和b的字元在c中順序保持不變。如 abc 和 xyz 可以被組合成 axbycz 或 abxcyz 等。我們定義字串的價值為其最長回文子串的長度 回文串表示從正反兩邊看完全一致的字串,如 aba 和 xyyx 需要求出所有可能的c中價值最大的字串,...

區間dp 合併回文子串

dp i j k p 表示a串的 i,j 和b串的 k,p 能否通過交叉且保持原有順序不變形成回文串。4維dp,先列舉長度,再列舉位置,狀態合法則貢獻答案。include using namespace std typedef long long ll 三年競賽一場空,不開long long見祖宗 ...