• lightoj-1013


    1013 - Love Calculator
    PDF (English) Statistics Forum
    Time Limit: 2 second(s) Memory Limit: 32 MB
    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

    解题思路: 玄学。。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    typedef long long ll;
    int dp[40][40];
    ll num[40][40];
    char str1[40],str2[40];
    
    int main(){
        
        int T,len1,len2;
        scanf("%d",&T);
        for(int t=1;t<=T;t++){
            memset(dp,0,sizeof(dp));
            memset(num,0,sizeof(num));
            
            scanf("%s %s",str1+1,str2+1);
            len1 = strlen(str1+1);
            len2 = strlen(str2+1);
            
            for(int i=0;i<=len1;i++) num[i][0] = 1;
            for(int i=0;i<=len2;i++) num[0][i] = 1;
            
            for(int i=1;i<=len1;i++){
                for(int j=1;j<=len2;j++){
                    
                    if(str1[i]==str2[j]){
                        dp[i][j] = dp[i-1][j-1]+1;
                        num[i][j] = num[i-1][j-1];
                    }else{
                        
                        if(dp[i-1][j]<dp[i][j-1]){
                            dp[i][j] = dp[i][j-1];
                            num[i][j] = num[i][j-1];
                        }else if(dp[i-1][j]>dp[i][j-1]){
                            dp[i][j] = dp[i-1][j];
                            num[i][j] = num[i-1][j];
                        }else{
                            dp[i][j] = dp[i-1][j];
                            num[i][j] = num[i-1][j] + num[i][j-1];
                        }
                        
                    }
                    
                }
            
                
            }
            
                printf("Case %d: %d %lld
    ",t,len1+len2-dp[len1][len2],num[len1][len2]);
        }
        
        return 0;
    }
  • 相关阅读:
    差分约束
    关系运算图。。。(差分约束)
    克鲁斯卡尔算法+并查集
    整体代换(数学)
    魔性の分块 | | jzoj1243 | | 线段树の暴力
    论人品 | | noip1015模拟考
    hash 表 | | jzoj 1335 | | 脑残+手残 | | 集合的关系
    凸轮大总结
    Floyd | | jzoj[1218] | | [Usaco2009 Dec]Toll 过路费 | | BZOJ 1774 | | 我也不知道该怎么写
    topsort | | jzoj[1226] | | NOIP2003神经网络
  • 原文地址:https://www.cnblogs.com/yuanshixingdan/p/5572241.html
Copyright © 2020-2023  润新知