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. Windows10中的IIS10安装php manager和IIS URL Rewrite 2.0组件的方法

    Windows10中自带的Server:Microsoft-IIS/10.0,然后这个10却让原本支持组件无法安装了,php manager组件安装时提示“必须安装IIS7以上才可以安装”.那是不是真 ...

  2. parseInt()、parseFloat()与Number()的比较

    我有一个同学最近在自学JavaScript,偶尔遇到问题了会让我帮忙解决,虽然我也是一个JavaScript菜鸟,但是我还是很乐意帮忙,这样不仅可以帮到别人,也可以让自己在解决问题的过程中学到更多知识 ...

  3. 安装mvc3出错致命错误

    给vs2010安装mvc3,出现如下错误提示: Installation failed with error code: (0x80070643), "安装时发生严重错误 ". 将 ...

  4. MVC控制器给View返回实体

    前言 这几天把vs12更新到了vs12 5了,因为发现我之前装的12有问题,没有mvc,之后就从itellyou上下载了12的update5更新了一下.说实话,从开发到现在,自己只是平时自己玩用mvc ...

  5. linear-gradient 的“高能”用法

    首先,让我们来了解一下“linear-gradient”的基本用法: 说明:用线性渐变创建图像 语法: <linear-gradient> = linear-gradient([ [ &l ...

  6. python基础学习(二)--函数

    return返回值: python函数都有返回值,函数体内无return,默认返回值None, 函数参数: 1.普通参数 严格按照顺序,将实际参数赋值给形式参数,一一对应. 例: def send(x ...

  7. 针对目前高校移动App的火热,哥决定点一把火

    最近正在做市场调研,还请众位大哥大姐们帮忙投个票,求扩散 http://user.qzone.qq.com/717010686/vote/00000000feb6bc2a3ebd1e53

  8. opengl混合效果

    效果如下图:

  9. shell写的计算器

    #!/bin/bashif [ $# -ne 3 ] then echo "Usage: $0 num1 + num2" fi case $2 in +) echo $1$2$3= ...

  10. web中自定义鼠标样式

    实现一个功能:鼠标移动到一个图片左边显示左箭头,移动到右边显示右箭头. 实现方法:一个img上面定位两个div,div的样式如下: .toleft { width: 200px; height: 30 ...