Cyborg Genes
题意:
给两个字符串,求最短的以两字符串为子序列的字符串和个数
分析:
最长公共子序列的变形,num[i][j]表示个数
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
char s1[],s2[];
int dp[][],num[][];
void solve(){
memset(dp,,sizeof(dp));
memset(num,,sizeof(num));
int l1=strlen(s1);
int l2=strlen(s2);
for(int i=;i<=l1;++i)
num[i][]=;
for(int i=;i<=l2;++i)
num[][i]=;
for(int i=;i<=l1;++i)
for(int j=;j<=l2;++j){
if(s1[i-]==s2[j-]){
dp[i][j]=dp[i-][j-]+;
num[i][j]=num[i-][j-];
}
else {
if(dp[i-][j]>dp[i][j-]){
dp[i][j]=dp[i-][j];
num[i][j]=num[i-][j];
}
else if(dp[i-][j]<dp[i][j-])
{
dp[i][j]=dp[i][j-];
num[i][j]=num[i][j-];
}
else {
dp[i][j]=dp[i-][j];
num[i][j]=num[i-][j]+num[i][j-];
}
}
}
printf("%d %d\n",l1+l2-dp[l1][l2],num[l1][l2]);
}
int main()
{
int t;
scanf("%d",&t);
getchar();
for(int c=;c<=t;++c)
{
gets(s1);
gets(s2);
printf("Case #%d: ",c);
solve();
}
return ;
}
Cyborg Genes的更多相关文章
- 10723 Cyborg Genes (LCS + 记忆化搜索)
Problem F Cyborg Genes Time Limit 1 Second September 11, 2132. This is the day that marks the beginn ...
- UVa 10723 LCS变形 Cyborg Genes
题解转自: UVA 10723 Cyborg Genes - Staginner - 博客园 首先这个题目肯定是按最长公共子序列的形式进行dp的,因为只有保证消去的一部分是最长公共子序列才能保证最后生 ...
- uva 10723 Cyborg Genes(LCS变形)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...
- UVa10723 - Cyborg Genes
这题我能想到的解决方法是: 最优解的长度好找,两串的长度和-LCS: 根据anslen,枚举出解的数目...但想不出简单有效的枚举方法,这种做法可能超时 网上看大神的博客后,发现大家都用的此方法: 最 ...
- UVA10723 电子人的基因 Cyborg Genes
题意翻译 [题目描述] 输入两个A~Z组成的字符串(长度均不超过30),找一个最短的串,使得输入的两个串均是它的子序列(不一定连续出现).你的程序还应统计长度最短的串的个数. e.g.:ABAAXGF ...
- UVA-10273 Cyborg Genes (DP)
题目大意:给两个字符串a.b,找出一个最短的字符串c,使得这两个字符串都是c的子序列.只需找出p的最小长度和最小长度时的个数. 题目分析:与LCS问题类似.最小长度的状态转移方程,dp(i,j)=mi ...
- UVa 10723 Cyborg Genes (LCS, DP)
题意:给定两行字符串,让你找出一个最短的序列,使得这两个字符串是它的子串,并且求出有多少种. 析:这个题和LCS很像,我们就可以利用这个思想,首先是求最短的长度,不就是两个字符串长度之和再减去公共的么 ...
- UVA - 10723 Cyborg Genes (LCS)
题目: 思路: 求两个串的最长公共子序列,则这个最短的串就是给出的两个串的长度和减去最长公共子序列的长度. 状态转移方程: 如果s[i-1]==t[j-1]就有dp[i][j] = dp[i-1][j ...
- 【Uva 10723】Cyborg Genes
[Link]: [Description] 给你两个串s1,s2; 让你生成一个串S; 使得s1和s2都是S的子列; 要求S最短; 求S的不同方案个数; [Solution] 设两个串的长度分别为n1 ...
随机推荐
- POJ1046Color Me Less
http://poj.org/problem?id=1046 据说这个题是个水题,但我还是WA了好几次,最后才改对了 #include<cstdio> #include<cstrin ...
- 恢复被win7覆盖的Ubuntu Grub
情景:本本装有Ubuntu 12.04 + Win7 32.重装Win7 64后,Ubuntu启动菜单被覆盖. 恢复的方法有多种,思路都一样.第一步,进入Linux环境:第二步.修改Grub使其重新覆 ...
- Sina App Engine(SAE)入门教程(2)-Mysql使用
如果你还没有SAE的账号,请在http://sae.sina.com.cn 注册新用户.具体的注册流程请参见:Sina App Engine(SAE)入门教程(1)在常规的环境下,我们可以通过http ...
- Android:实现数组之间的复制
System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制 System.arraycopy(src, srcPos, dst, dstPos, length); src ...
- Docker实例教程[超详细](一)
Docker Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互 ...
- 自定义View(6)paint设置图图层重叠时的显示方式,包含清空canvas
Paint.setXfermode 这个函数设置两个图层相交时的模式 在已有的图层上绘图将会在其上面添加一层新的图层. 如果新的图层是完全不透明的,那么它将完全遮挡住下面的图层,而setXfermod ...
- ConcurrentDictionary和Dictionary
http://stackoverflow.com/questions/6739193/is-the-concurrentdictionary-thread-safe-to-the-point-that ...
- SQLiteParameter不能将TableName作为参数
http://stackoverflow.com/questions/1274432/sqlite-parameters-not-allowing-tablename-as-parameter Gen ...
- 【转载】React入门-Todolist制作学习
我直接看的这个React TodoList的例子(非常好!): http://www.reqianduan.com/2297.html 文中示例的代码访问路径:http://127.0.0.1:708 ...
- QWidget、QDialog、QMainWindow的异同点
简述 在分享所有基础知识之前,很有必要在这里介绍下常用的窗口 - QWidget.QDialog.QMainWindow. QWidget继承于QObject和QPaintDevice,QDialog ...