lightoj-1013 - Love Calculator(lcs变体)

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\n",t,len1+len2-dp[len1][len2],num[len1][len2]);
    }

    return 0;
}
时间: 2024-08-03 10:14:32

lightoj-1013 - Love Calculator(lcs变体)的相关文章

DP [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' ac

从头认识java-18.2 基本的线程机制(6)-使用构造器或者内部类来实现多线程的编码变体

这一章节我们来讨论一下使用构造器或者内部类来实现多线程的编码变体. 1.基础实现 package com.ray.ch17; public class Test { public static void main(String[] args) { Thread thread1 = new ExtendsThread(); thread1.start(); Thread thread2 = new Thread(new ImplRunnable()); thread2.start(); } } c

变体(协变与逆变)

变体的引入是为了提高泛型类型的变量在赋值时可以对类型进行兼容性转换,以扩展泛型的灵活性.下面看个例子: public delegate void DoWork<T>(T arg); ........ DoWork<A> del1=delegate(A arg){//.......}; DoWork<B> del2=del1; B bb=new B(); del2(bb); 其中A ,B是两个类,B类继承A类,即:public class A{.....}        

labview 变体

变体数据类型是LabVIEW中多种数据类型的容器.将其它数据转换为变体时,变体将存储数据和数据的原始类型,保证日后可将变体数据反向转换. 例如,如将字符串数据转换为变体,变体将存储字符串的文本,以及说明该数据是从字符串(而不是路径.字节数组或其它LabVIEW数据类型)转换而来的信息. 变体函数可用于创建和操作变体数据.可将平化数据和LabVIEW数据转化为变体数据,或将变体数据转化为LabVIEW数据. 变体数据类型可存储数据的属性.属性是定义的数据及变体数据类型所存储的数据的信息. 例如,如

Android Studio下项目构建的Gradle配置及打包应用变体

Gradle简介 ??Gradle是一个自动化构建工具,采用Groovy的Domain Specific Language(领域特定语言)来描述和控制构建逻辑.具有语法简洁.可读性强.配置灵活等特点.基于Intellij IDEA社区版本开发的Android Studio天生支持Gradle构建程序.Groovy是一种基于JVM的敏捷开发语言,结合了Phthon.Ruby和Smalltalk的许多强大特性.同时,Groovy代码既能够与java代码很好地结合,也能够用于扩展现有的代码. Grad

(转) 干货 | 图解LSTM神经网络架构及其11种变体(附论文)

干货 | 图解LSTM神经网络架构及其11种变体(附论文) 2016-10-02 机器之心 选自FastML 作者:Zygmunt Z. 机器之心编译  参与:老红.李亚洲 就像雨季后非洲大草原许多野生溪流分化成的湖泊和水洼,深度学习已经分化成了各种不同的专门架构. 并且,每个架构都会有一个图解,这里将详细介绍它们. 神经网络在概念上很简单,并且它们十分动人.在层级上,有着一堆同质化的元素和统一的单位,并且它们之间还存在在一系列的加权连接.这就是神经网络的所有,至少从理论上来说是这样.然而,时间

5.2 vector: 创建和使用vector的各种变体

Clojure练习-5.组合数据类型 "用100个函数来操作一个数据结构比10个函数操作10个数据结构要好很多.基于一个统一的数据结构,我们可以构建出一系列的小函数,这些小函数又可以组合起来形成一个强大的系统.而为不同的数据结构编写不同的函数,在根本上就削减了复用的可能." -- [ Alan Perlis ] Clojure练习-5组合数据类型 组合数据类型 2 vector 创建和使用vector的各种变体 已知 解1 测试 解2 测试 5. 组合数据类型 5.2 vector:

uva10635 Prince and Princess LCS 变 lIS

// uva10635 Prince and Princess LCS 变 lIS // 本意求LCS,但是规模有60000多,复杂度肯定不够 // 注意如果俩个序列的值的范围相同,那么可以在一个 // 串中记录在另外一个串中的位置.这样就可以转化成 // 最长上升子序列的问题啦,复杂度是nlogn,可以ac // 这题,还是挺有考究的价值的,很不错 // 哎,继续练吧..... #include <algorithm> #include <bitset> #include <

单例模式变体

/**饿汉模式*/ public class EagerSingleton { private static EagerSingleton eagerSingleton=new EagerSingleton(); private EagerSingleton() { super(); } public static EagerSingleton getInstance(){ return eagerSingleton; }} /* *懒汉模式 *优点: 不使用就不创建, 节省内存空间.  * 缺