[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' according to their names. The software requires the following things:
- The length of the shortest string that contains the names as subsequence.
- 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的更多相关文章
- Light oj 1013 - Love Calculator (LCS变形)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1013 题意: 给你两个字符串,让你构造出一个长度最小的字符串,且它的子序列包含 ...
- Light OJ 1013 Love Calculator(DP)
题目大意: 给你两个字符串A,B 要求一个最短的字符串C,使得A,B同时为C的子串. 问C最短长度是多少? C有多少种? 题目分析: 做这道题目的时候自己并没有推出来,看了网上的题解. 1.dp[C串 ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ Dynamic Programming
免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- How to Change Password Complexity Requirements in Windows XP
Original Link: http://www.ehow.com/how_4812793_password-complexity-requirements-windows-xp.html#ixzz ...
- Integer ,==,int 的使用
面试比较常见的题目:自己也经常忘记,所以就记下来了 上代码: Integer a = ,b=; Integer c = ,d=; System.out.println(a==b); System.ou ...
- php二维数组,按照指定的key,去排序value值
$arr = array( '11'=>array( 'a'=>1, 'b'=>2, ), '22'=>array( 'a'=>3, 'b'=>4, ), '33' ...
- 正确理解javascript的this关键字
javascript有this关键字,它和javascript的执行上下文有着密切的关系,就是说this具体指代什么要根据它的上下文来判断. 一.this和对象的关系 var Person={ ...
- 在linux下安装memcacheq
#!/bin/bash mkdir ~/build cd ~/build wget http://download.oracle.com/berkeley-db/db-5.1.19.tar.gz .t ...
- 解决IE 下div与img重叠无法触发鼠标事件的问题
在IE下当我想在img标签上层显示一个div元素时,此时如果该div的background为空白(没有设置图片.或者颜色填充),会导致该div的鼠标事件失效:如果设置border为1px solid ...
- Bind Enum to ListControl
当使用MVVM时,相信你和我一样经常有这样的需求: 在ViewModel里定义了一个Enum,它必然是对应UI上的一个ListControl作为不同选项. 有一种做法是使用Converter,将Enu ...
- EasyUI portal自定义小图标,不是用js方式加载
<script src="~/Scripts/jquery.portal.js"></script> <script> $(function ( ...
- poj 3261 Milk Patterns(后缀数组)(k次的最长重复子串)
Milk Patterns Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7938 Accepted: 3598 Cas ...
- ubuntu terminal 介绍及相关命令
ubuntu的terminal 1.调出方法 windows键+T 2.终端显示内容 3. 查看当前所在目录的绝对路径--pwd命令 eg1: eg2: linux严格区分大小写 4. 更改/进入目录 ...