## Welcome To SDIBT ACM-ICPC Online Judge

Problem 1095. -- Distinct Subsequences## Distinct Subsequences

Time Limit: 1 Sec Memory Limit: 64 MB

Submit: 2 Solved: 2

[Submit][Status][Discuss]## Description

A subsequence of a given sequence S consists of S with zero or more elements deleted. Formally, a sequence *Z* = *z*_{1}*z*_{2}...*z*_{k}
is a subsequence of *X* = *x*_{1}*x*_{2}...*x*_{m} if there exists a strictly increasing sequence < i1, i2,..., ik > of indices of X such that for all j = 1, 2,..., k, we have *x*_{ij} = *z*_{j}. For example, Z = bcdb is a subsequence of X = abcbdab with corresponding index sequence < 2, 3, 5, 7 >.
Your job is to write a program that counts the number of occurrences of Z in X as a subsequence such that each has a distinct index sequence.

## Input

The first line of the input contains an integer N indicating the number of test cases to follow. The first line of each test case contains a string X, composed entirely of lowercase alphabetic characters and having length no greater than 10,000. The second line contains another string Z having length no greater than 100 and also composed of only lowercase alphabetic characters. Be assured that neither Z nor any prefix or suffix of Z will have more than 10100 distinct occurrences in X as a subsequence.

## Output

For each test case, output the number of distinct occurrences of Z in X as a subsequence.
Output for each input set must be on a separate line.

## Sample Input

2
babgbag
bag
rabbbit
rabbit

## Sample Output

5
3

## HINT

## Source

[Submit][Status][Discuss]

HOME
Back

한국어 中文 English

All Copyright Reserved 2008-2010 SDIBT TEAM

GPL2.0 2003-2010 HUSTOJ Project TEAM

Anything about the Problems, Please Contact Admin:admin