贵阳市网站建设,手工制作花,沈阳想做网站,建设部网站在哪里看受理传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你两个串s,ts,ts,t#xff0c;每次都可以从sss的开头拿一个字符放到AAA串的开头或结尾#xff0c;问最终有多少种方案使得ttt是AAA的前缀#xff0c;注意sss不必全部拿完。 m,n≤3000m,n\le3000m,n≤30…传送门
文章目录题意思路题意
给你两个串s,ts,ts,t每次都可以从sss的开头拿一个字符放到AAA串的开头或结尾问最终有多少种方案使得ttt是AAA的前缀注意sss不必全部拿完。 m,n≤3000m,n\le3000m,n≤3000
思路
分析一下题目的性质每次都给一个串从前面或从后面加一个字符相当于从两边扩展长度可以联想到区间dpdpdp。 设f[l][r]f[l][r]f[l][r]表示用sss的前r−l1r-l1r−l1个字符拼成ttt的[l,r][l,r][l,r]的方案数有一个很明显的转移方程f[l][r]f[l1][r](s[len]t[l])f[l][r]f[l1][r](s[len]t[l])f[l][r]f[l1][r](s[len]t[l])f[l][r]f[l][r−1](s[len]t[r])f[l][r]f[l][r-1](s[len]t[r])f[l][r]f[l][r−1](s[len]t[r]) 直接这么写是不对的因为我们发现s,ts,ts,t的长度不相等也就是说如果lenmlenmlenm的话有一部分放的时候是没有要求的具体来说 (1)(1)(1)当lmlmlm的时候它可以放在lll的位置也可以放在rrr的位置。 (2)(2)(2)当rmrmrm的时候它可以放在rrr的位置。 所以转移的时候判断一下这两个条件就好啦。 初始的时候f[i][i]2∗(im∣∣s[1]t[i])f[i][i]2*(im||s[1]t[i])f[i][i]2∗(im∣∣s[1]t[i])。 最终答案为∑imnf[1][i]\sum_{im}^nf[1][i]∑imnf[1][i]。
// Problem: C. Kaavi and Magic Spell
// Contest: Codeforces - Codeforces Round #635 (Div. 1)
// URL: https://codeforces.com/problemset/problem/1336/C
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].ltr[u].r1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N3010,mod998244353,INF0x3f3f3f3f;
const double eps1e-6;char a[N],b[N];
LL f[N][N];int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);scanf(%s%s,a1,b1);int nstrlen(a1),mstrlen(b1);for(int i1;in;i) if(im||a[1]b[i]) f[i][i]2;for(int len2;lenn;len) {for(int l1;llen-1n;l) {int rllen-1;if(lm||a[len]b[l]) f[l][r]f[l1][r]; f[l][r]%mod;if(rm||a[len]b[r]) f[l][r]f[l][r-1]; f[l][r]%mod;}}LL ans0; for(int im;in;i) ansf[1][i],ans%mod;printf(%d\n,ans%mod);return 0;
}
/**/