Loading docs/string/pam.md +5 −4 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ using namespace std; typedef long long ll; const int maxn = 300000 + 5; ``` namespace pam { int sz, tot, last; Loading Loading @@ -250,7 +251,6 @@ border:若 $0 \le r < |s|$ , $pre(s,r)=suf(s,r)$ ,就称 $pre(s,r)$ 是 $s 给定一个字符串 $s$ ,要求将 $s$ 划分为 $t_1, t_2, \dots, t_k$ ,其中 $k$ 是偶数,且 $t_i=t_{k-i}$ ,求这样的划分方案数。 ??? note "题解" 构造字符串 $t= s[0]s[n - 1]s[1]s[n - 2]s[2]s[n - 3] \dots s[n / 2 - 1]s[n / 2]$ ,问题等价于求 $t$ 的偶回文划分方案数,把上面的转移方程改成求和形式并且只在偶数位置更新 $dp$ 数组即可。时间复杂度 $O(n \log n)$ ,空间复杂度 $O(n)$ 。 Loading @@ -261,6 +261,7 @@ border:若 $0 \le r < |s|$ , $pre(s,r)=suf(s,r)$ ,就称 $pre(s,r)$ 是 $s typedef long long ll; const int mod = 1e9 + 7; const int maxn = 1000000 + 5; ``` inline int add(int x, int y) { x += y; Loading Loading
docs/string/pam.md +5 −4 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ using namespace std; typedef long long ll; const int maxn = 300000 + 5; ``` namespace pam { int sz, tot, last; Loading Loading @@ -250,7 +251,6 @@ border:若 $0 \le r < |s|$ , $pre(s,r)=suf(s,r)$ ,就称 $pre(s,r)$ 是 $s 给定一个字符串 $s$ ,要求将 $s$ 划分为 $t_1, t_2, \dots, t_k$ ,其中 $k$ 是偶数,且 $t_i=t_{k-i}$ ,求这样的划分方案数。 ??? note "题解" 构造字符串 $t= s[0]s[n - 1]s[1]s[n - 2]s[2]s[n - 3] \dots s[n / 2 - 1]s[n / 2]$ ,问题等价于求 $t$ 的偶回文划分方案数,把上面的转移方程改成求和形式并且只在偶数位置更新 $dp$ 数组即可。时间复杂度 $O(n \log n)$ ,空间复杂度 $O(n)$ 。 Loading @@ -261,6 +261,7 @@ border:若 $0 \le r < |s|$ , $pre(s,r)=suf(s,r)$ ,就称 $pre(s,r)$ 是 $s typedef long long ll; const int mod = 1e9 + 7; const int maxn = 1000000 + 5; ``` inline int add(int x, int y) { x += y; Loading