比赛 |
2022级DP专题练习赛1 |
评测结果 |
AAAAAAAAA |
题目名称 |
管道取珠 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.680 s |
代码语言 |
C++ |
内存使用 |
3.41 MiB |
提交时间 |
2023-02-10 19:05:47 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=500+5;
const int mod=1024523;
int n,m;
int f[2][N][N],now=0;
char a[N],b[N];
int main(){
freopen ("ballb.in","r",stdin);
freopen ("ballb.out","w",stdout);
scanf("%d%d",&n,&m);
scanf("%s%s",a+1,b+1);
f[now][0][0]=1;
for (int i=0;i<=n;i++){
for (int j=0;j<=m;j++){
for (int k=max(0,i+j-m);k<=min(i+j,n);k++){
int l=i+j-k;
if (a[i+1]==a[k+1])f[now^1][j][k+1]=(f[now^1][j][k+1]+f[now][j][k])%mod;
if (a[i+1]==b[l+1])f[now^1][j][k]=(f[now^1][j][k]+f[now][j][k])%mod;
if (b[j+1]==a[k+1])f[now][j+1][k+1]=(f[now][j+1][k+1]+f[now][j][k])%mod;
if (b[j+1]==b[l+1])f[now][j+1][k]=(f[now][j+1][k]+f[now][j][k])%mod;
f[now][j][k]=0;
}
}
now^=1;
}
printf("%d\n",f[now][m][n]);
return 0;
}