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[];
char s2[];
ll dp[][][]; //dp[i][j][k]表示当长度为k时,包含第1个串中前i个字符,第2个串中前j个字符的方案数。 int main()
{
ll i,j,k,T,iCase=;
scanf("%lld",&T);
while(T--)
{
memset(dp,,sizeof(dp));
scanf("%s%s",s1+,s2+);
l1=strlen(s1+);
l2=strlen(s2+);
for(i=;i<=l1;i++) dp[i][][i]=;
for(j=;j<=l2;j++) dp[][j][j]=; //注意初始化细节
for(k=;k<=l1+l2;k++)
{
for(i=;i<=l1;i++)
{
for(j=;j<=l2;j++)
{
if(s1[i]==s2[j])
{
dp[i][j][k]+=dp[i-][j-][k-];
}
else
{
dp[i][j][k]+=dp[i-][j][k-]+dp[i][j-][k-];
}
}
}
}
for(k=;k<=l1+l2;k++)
{
if(dp[l1][l2][k])
{
break;
}
}
printf("Case %lld: %lld %lld\n",iCase++,k,dp[l1][l2][k]);
}
return ;
}

[light oj 1013] Love Calculator的更多相关文章

  1. Light oj 1013 - Love Calculator (LCS变形)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1013 题意: 给你两个字符串,让你构造出一个长度最小的字符串,且它的子序列包含 ...

  2. Light OJ 1013 Love Calculator(DP)

    题目大意: 给你两个字符串A,B 要求一个最短的字符串C,使得A,B同时为C的子串. 问C最短长度是多少? C有多少种? 题目分析: 做这道题目的时候自己并没有推出来,看了网上的题解. 1.dp[C串 ...

  3. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  4. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  5. Light OJ Dynamic Programming

    免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...

  6. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  7. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  8. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  9. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

随机推荐

  1. C#语法需要注意的地方

    笔试中遇到的一些C#语法方面的问题,由于平时很少用到,笔试的时候模棱两可,现在做一个笔记. using System; using System.Collections.Generic; using ...

  2. 【原创】开机出现grub rescue,修复办法

    出现这种问题 一般在于进行了磁盘分区(GHOST备份时也会造成)导致grub引导文件找不到.我们只要让它找到引导文件就好了. 此时屏幕上提示grub resume>  我们先输入set看下现在g ...

  3. Javascript 中 null、NaN和undefined的区别

    1.类型分析: js中的数据类型有undefined,boolean,number,string,object等5种,前4种为原始类型,第5种为引用类型. 代码 var a1; var a2 = tr ...

  4. c#的多线程

    多线程的使用方法: Thread t = new Thread(new ThreadStart (StartMethod)); t.Start(); private void StartMethod( ...

  5. (转)互联网协议入门 ------ HTTP(1)

    作者:阮一峰 原文:http://www.ruanyifeng.com/blog/2012/06/internet_protocol_suite_part_ii.html 我们每天使用互联网,你是否想 ...

  6. 原创:Javascript Websocket客户端封装

    调试中,马马虎虎能用var LeesWebSocket = function (options) { this.defaults = { host: "127.0.0.1", po ...

  7. Android开发第1篇 - Android开发环境搭建

    归结一下,需要进行Android开发所需要的工具或软件: Eclipse - Android是基于JAVA的开发,所以选用目前来说使用较高的Eclipse作为IDE. ADT (Android Dev ...

  8. opengl多重采样

    效果图如下,两幅图效果是一样的,只是换了个背景.两幅图均是左侧使用了多重采样,右侧的没有使用多重采样.

  9. Java EJX

    EJX http://www.docin.com/p-121548732.html

  10. 树莓派2 安装mono3.0运行mvc4

    sudo apt-get updatesudo apt-get upgradesudo apt-get mono-completewget -c http://www.linuxdot.net/dow ...