/* >>~~ UVa Online Judge ACM Problem Solution ~~<< ID: 10069 Name: Distinct Subsequences Problem: https://onlinejudge.org/external/100/10069.pdf Language: C++ Author: Arash Shakery Email: arash.shakery@gmail.com */ #include #include #include #include #include #include #include using namespace std; class BigInt { typedef int CellType; const static int CellSize = sizeof(CellType); const static int MAX_C = 10000; const static int MAX_D = 4; CellType *cells; int capacity, size, sign; int sgn(int x) { return x<0 ? -1 : x>0 ? 1 : 0; } void init() { sign = size = 0; cells = new CellType[capacity = 100]; memset(cells, 0, 4*CellSize); } int setSize(int sz, bool cp = true) { return size = sz; } BigInt& autoSize() { while (size>0 && !cells[size-1]) size--; if (!size) sign=0; return *this; } public: BigInt() { init(); } BigInt(int x) { init(); sign = sgn(x); x*=sign; for (size=0; x; size++) { cells[size] = x % MAX_C; x /= MAX_C; } } BigInt(const BigInt& o): cells(0), capacity(0) { init(); sign = o.sign; setSize(o.size, 0); for (int i=0; i= 0) delete [] cells; } public: void setZero() { sign = size = cells[0] = 0; } void setOne() { sign = size = cells[0] = 1; } bool isZero() { return sign==0; } BigInt& operator=(const BigInt &o) { sign = o.sign; size = o.size; for (int i=0; i= MAX_C ) { cells[i] -= MAX_C; cells[i+1]++; } return autoSize(); } // --------------------------------------------------------------------- friend std::ostream& operator<< (std::ostream& stream, const BigInt& bs) { if (!bs.sign) stream << 0; else { if (bs.sign < 0) stream << '-'; stream << bs.cells[bs.size-1]; for (int i=bs.size-2; i>=0; i--) stream << setfill('0') << setw(MAX_D) << bs.cells[i]; } return stream; } }; char s1[10016], s2[117]; BigInt DP[10017][103]; int main(){ int T; scanf("%d", &T); while (T--) { scanf("%s%s", s1, s2); int l1=strlen(s1), l2=strlen(s2); if (l1 < l2) puts("0"); else { for (int i=0; i