zoukankan      html  css  js  c++  java
  • [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
    ",iCase++,k,dp[l1][l2][k]);
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    djongo 前端页面展示自定义api返回的列表数据,并拼接到table上
    ou are trying to add a non-nullable field 'address' to person without a default; we can't do that (the database needs something to populate existing rows).
    python string 类型的公钥转换类型并解密
    Django 禁止访问403,CSRF验证失败,相应中断
    springboot async
    此博客可能不再更新,往后博文将发布在 GitHub 中
    css 中 transition 需要注意的问题
    学习笔记(九)
    微信小程序 drawImage 问题
    学习笔记(八)
  • 原文地址:https://www.cnblogs.com/hate13/p/4192616.html
Copyright © 2011-2022 走看看