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. forever start Error: Cannot find module './daemon.v0.10.26'

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3590158.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  2. mysql 常用命令搜集

    查看MYSQL数据库中所有用户及拥有权限 mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query F ...

  3. hdu 5014 Number Sequence

    为了a异或b的和最大,只需另b在不大于n的情况下按位取反即可. 这里有两个输出小技巧可以参考: 1.在用printf输出__int64时,在windows下使用格式"%I64d", ...

  4. Linux内核Radix Tree(三):API介绍

    1.     单值查找radix_tree_lookup 函数radix_tree_lookup执行查找操作,查找方法是:从叶子到树顶,通过数组索引键值值查看数组元素的方法,一层层地查找slot.其列 ...

  5. javascript控制子页面对父页面控件操作

    //赋值 window.parent.document.getElementById("partyid_trade_edit").value = data.data.partyid ...

  6. Jquery Offset, Document, Window 都是什么

    From http://www.cnblogs.com/luhe/archive/2012/11/14/2769263.html   JQuery Offset实验与应用 我们有时候需要实现这样一种功 ...

  7. call_user_func_array

    call_user_func_array — 调用回调函数,并把一个数组参数作为回调函数的参数 参数 callback 被调用的回调函数. param_arr 要被传入回调函数的数组,这个数组得是索引 ...

  8. 详解MySQL中EXPLAIN解释命令(转)

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...

  9. Spring MVC 注解和XML的区别

      注解与XML配置的区别 注解:是一种分散式的元数据,与源代码紧绑定. xml:是一种集中式的元数据,与源代码无绑定. 因此注解和XML的选择上可以从两个角度来看:分散还是集中,源代码绑定/无绑定. ...

  10. JS 操作URL(重要)

    我们可以用javascript获得其中的各个部分1, window.location.href全部URl字符串(在浏览器中就是完整的地址栏)本例返回值: http://www.x2y2.com:80/ ...