[light oj 1013] Love Calculator

1013 - Love Calculator

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:

  1. The length of the shortest string that contains the names as subsequence.
  2. 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

Output for Sample Input

3

USA

USSR

LAILI

MAJNU

SHAHJAHAN

MOMTAJ

Case 1: 5 3

Case 2: 9 40

Case 3: 13 15

 

 

 

 

 

 

 

 

 

 

做了这个题、只剩下泪了。

最开始记忆化搜索,不造哪里错了Wa。

然后DP、然后把l2写成了12,恰好样例又过了,Wa,各种测试,还以为编译器出问题了

然后改之,由于最开始把数组开大了,超内存,然后改小,然后不造怎么的,数组一变小就输出一串莫名其妙的数字,Ac后才发现好像是中途数组下标为-1越界的原因。

然后改之,由于初始化看错了,过了讨论里所有数据,Wa在第一组,输出6 2。

最后改之,Ac。

受不了,- -

我是二货!

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 0x7fffffff
#define ll long long

ll l1,l2;
char s1[33];
char s2[33];
ll dp[33][33][66];  //dp[i][j][k]表示当长度为k时,包含第1个串中前i个字符,第2个串中前j个字符的方案数。

int main()
{
    ll i,j,k,T,iCase=1;
    scanf("%lld",&T);
    while(T--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%s%s",s1+1,s2+1);
        l1=strlen(s1+1);
        l2=strlen(s2+1);
        for(i=0;i<=l1;i++) dp[i][0][i]=1;
        for(j=0;j<=l2;j++) dp[0][j][j]=1;  //注意初始化细节
        for(k=1;k<=l1+l2;k++)
        {
            for(i=1;i<=l1;i++)
            {
                for(j=1;j<=l2;j++)
                {
                    if(s1[i]==s2[j])
                    {
                        dp[i][j][k]+=dp[i-1][j-1][k-1];
                    }
                    else
                    {
                        dp[i][j][k]+=dp[i-1][j][k-1]+dp[i][j-1][k-1];
                    }
                }
            }
        }
        for(k=1;k<=l1+l2;k++)
        {
            if(dp[l1][l2][k])
            {
                break;
            }
        }
        printf("Case %lld: %lld %lld\n",iCase++,k,dp[l1][l2][k]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/hate13/p/4192616.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值