Pagini recente » Cod sursa (job #2216792) | Cod sursa (job #2453278) | Cod sursa (job #2224234) | Cod sursa (job #59856) | Cod sursa (job #165448)
Cod sursa(job #165448)
#include <stdio.h>
#include <string.h>
#define nmax 22
char A[nmax], B[nmax];
int N, M, P, ans, NRP[nmax][nmax][nmax];
void read()
{
freopen("iv.in", "r", stdin);
scanf("%s", &A);
scanf("\n");
scanf("%s", &B);
}
void solve()
{
int i, x, y;
N = strlen(A);
M = strlen(B);
for (i = N; i >= 1; i--)
A[i] = A[i-1];
for (i = M; i >= 1; i--)
B[i] = B[i-1];
A[0] = B[0] = ' ';
// pentru cazul elementar
if (A[1] == A[N])
NRP[1][1][1] = 1;
if (A[1] == B[M])
NRP[1][1][0] = 1;
if (B[1] == A[N])
NRP[1][0][1] = 1;
if (B[1] == B[M])
NRP[1][0][0] = 1;
for (i = 2, P = (M+N)/2 + (M+N)%2; i <= P; ++i)
for (x = 0; x <= i; ++x)
for (y = 0; y <= i; ++y)
{
if (x > 0 && N-y+1 <= N && A[x] == A[N-y+1])
NRP[i][x][y] += NRP[i-1][x-1][y-1];
if (x > 0 && M-i+y+1 <= M && A[x] == B[M-i+y+1])
NRP[i][x][y] += NRP[i-1][x-1][y];
if (i-x > 0 && N-y+1 <= N && B[i-x] == A[N-y+1])
NRP[i][x][y] += NRP[i-1][x][y-1];
if (i-x > 0 && M-i+y+1 <= M && B[i-x] == B[M-i+y+1])
NRP[i][x][y] += NRP[i-1][x][y];
}
for (x = 0; x <= P; ++x)
for (y = 0; y <= P; ++y)
ans += NRP[P][x][y];
ans /= 2;
}
void write()
{
freopen("iv.out", "w", stdout);
printf("%d\n", ans);
}
int main()
{
read();
solve();
write();
return 0;
}