简单的dp 但是一个大数加法 套用了末位大牛的类模板
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxs 10005
#define maxn 110
using namespace std;
char X[maxs], Z[maxn];
struct bign
{
int len, s[maxn];
bign operator = (const char *num)
{
len = strlen(num);
for (int i = 0; i < len; i++)
s[i] = num[len-i-1]-'0';
return *this;
}
bign operator + (const bign &b) const
{
bign c; c.len = 0;
for (int i = 0, g = 0; g || i < max(len, b.len); i++)
{
int x = g;
if (i < len) x += s[i];
if (i < b.len) x += b.s[i];
c.s[c.len++] = x%10;
g = x/10;
}
return c;
}
bign operator += (const bign &b)
{
*this = *this + b;
return *this;
}
void print()
{
for (int i = len-1; i >= 0; i--)
printf("%d", s[i]);
}
};
bign dp[maxn][maxs];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s%s", X+1, Z+1);
int len1 = strlen(X+1), len2 = strlen(Z+1);
for (int i = 0; i <= len1; i++)
dp[0][i] = "1";
for (int i = 1; i <= len2; i++)
for (int j = i; j <= len1; j++)
{
dp[i][j] = dp[i][j-1];
if (Z[i] == X[j])
dp[i][j] += dp[i-1][j-1];
}
dp[len2][len1].print();
//printf("%d",dp[len2][len1]);
puts("");
}
return 0;
}