您的位置:首页 > 其它

【LightOJ 1013】Love Calculator(LCS+DP)

2016-07-26 20:17 489 查看

Problem Description

Yes, you are developing a ‘Love calculator’. The software would be quite complex such that nobody could crack the exact behavior of the software.

So, given two names your software will generate the percentage of their ‘love’ according to their names. The software requires the following things:

The length of the shortest string that contains the names as subsequence.

Total number of unique shortest strings which contain the names as subsequence.

Now your task is to find these parts.

Input

Input starts with an integer T (≤ 125), denoting the number of test cases.

Each of the test cases consists of two lines each containing a name. The names will contain no more than 30 capital letters.

Output

For each of the test cases, you need to print one line of output. The output for each test case starts with the test case number, followed by the shortest length of the string and the number of unique strings that satisfies the given conditions.

You can assume that the number of unique strings will always be less than 263. Look at the sample output for the exact format.

Sample Input

3

USA

USSR

LAILI

MAJNU

SHAHJAHAN

MOMTAJ

Output for Sample Input

Case 1: 5 3

Case 2: 9 40

Case 3: 13 15

题目大意

给你两个串s1,s2,要求找到一个串,并且这个串的字串包含s1,s2同时要尽量使这个串的长度小,输出这个串的长度并输出方案个数(因为串不唯一)。

思路

对于所求串的长度很好理解,就是两个串的长度之和减去他们的公共字串的长度。但是对于方案个数的求法就比较复杂,可以用一个三维数组cnt[i][j][url=0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: