Pagini recente » Cod sursa (job #1287763) | Cod sursa (job #1695556) | Autentificare | Cod sursa (job #2227472) | Cod sursa (job #605883)
Cod sursa(job #605883)
#include <stdio.h>
#include <string.h>
#define LMax 510
const char IN[]="iv.in",OUT[]="iv.out";
const int mod=3210121;
int La,Lb;
char a[LMax] , b[LMax];
int T[2][LMax][LMax];
int solve()
{
int p1,p2,p3,p4;
for (p1=La-1;p1>=0;--p1)
{
for (p2=p1;p2<La;++p2)
for (p3=Lb-1;p3>=0;--p3)
{
p4= La - p3 -1 + 1 + Lb + 1 - p1-1 - p2-1 -1;
if (p1==p2 && p3==p4) {T[0][p2][p3]=2;continue;}
T[0][p2][p3]=0;
if (a[p1]==b[p4]) T[0][p2][p3]+= T[1][p2][p3];
if (a[p1]==a[p2]) T[0][p2][p3]+= T[1][p2-1][p3];
if (b[p3]==b[p4]) T[0][p2][p3]+= T[0][p2][p3+1];
if (a[p2]==b[p3]) T[0][p2][p3]+= T[0][p2-1][p3+1];
T[0][p2][p3]%=mod;
}
memcpy(T[1],T[0],sizeof(T[1]));
}
return T[1][La-1][0];
}
int main()
{
freopen(IN,"r",stdin);
fgets( a , LMax , stdin );
fgets( b , LMax , stdin );
fclose(stdin);
La=strlen(a)-1;Lb=strlen(b)-1;
int r=solve();
freopen(OUT,"w",stdout);
printf("%d\n",r);
fclose(stdout);
return 0;
}