题意:

给两个字符串,求最短的以两字符串为子序列的字符串和个数

分析:

最长公共子序列的变形,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的更多相关文章

  1. 10723 Cyborg Genes (LCS + 记忆化搜索)

    Problem F Cyborg Genes Time Limit 1 Second September 11, 2132. This is the day that marks the beginn ...

  2. UVa 10723 LCS变形 Cyborg Genes

    题解转自: UVA 10723 Cyborg Genes - Staginner - 博客园 首先这个题目肯定是按最长公共子序列的形式进行dp的,因为只有保证消去的一部分是最长公共子序列才能保证最后生 ...

  3. uva 10723 Cyborg Genes(LCS变形)

    题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...

  4. UVa10723 - Cyborg Genes

    这题我能想到的解决方法是: 最优解的长度好找,两串的长度和-LCS: 根据anslen,枚举出解的数目...但想不出简单有效的枚举方法,这种做法可能超时 网上看大神的博客后,发现大家都用的此方法: 最 ...

  5. UVA10723 电子人的基因 Cyborg Genes

    题意翻译 [题目描述] 输入两个A~Z组成的字符串(长度均不超过30),找一个最短的串,使得输入的两个串均是它的子序列(不一定连续出现).你的程序还应统计长度最短的串的个数. e.g.:ABAAXGF ...

  6. UVA-10273 Cyborg Genes (DP)

    题目大意:给两个字符串a.b,找出一个最短的字符串c,使得这两个字符串都是c的子序列.只需找出p的最小长度和最小长度时的个数. 题目分析:与LCS问题类似.最小长度的状态转移方程,dp(i,j)=mi ...

  7. UVa 10723 Cyborg Genes (LCS, DP)

    题意:给定两行字符串,让你找出一个最短的序列,使得这两个字符串是它的子串,并且求出有多少种. 析:这个题和LCS很像,我们就可以利用这个思想,首先是求最短的长度,不就是两个字符串长度之和再减去公共的么 ...

  8. UVA - 10723 Cyborg Genes (LCS)

    题目: 思路: 求两个串的最长公共子序列,则这个最短的串就是给出的两个串的长度和减去最长公共子序列的长度. 状态转移方程: 如果s[i-1]==t[j-1]就有dp[i][j] = dp[i-1][j ...

  9. 【Uva 10723】Cyborg Genes

    [Link]: [Description] 给你两个串s1,s2; 让你生成一个串S; 使得s1和s2都是S的子列; 要求S最短; 求S的不同方案个数; [Solution] 设两个串的长度分别为n1 ...

随机推荐

  1. VisualSVN Server的windows 2003配置和使用方法(图文并茂)

    1.为什么要用VisualSVN Server,而不用Subversion? 回答: 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Serve ...

  2. Python新式类和旧式类的区别

    新式类是为了统一**而在2.2中开始引入的. 代码讲解 上面的例子比较明白的说明了问题. B是定义的新式类.那么输入b的时候,不论是type(b),还是b.__class__都是输出的<clas ...

  3. keystonejs

    开始之前先确保你已经安装了Node.js 0.10+ 和MongoDB v2.4+. 要使用KeystoneJS,你需要掌握合理的Javascript知识,并熟悉数据库概念之类的基础知识,会用 nod ...

  4. Linux中断(interrupt)子系统

    Linux中断(interrupt)子系统之一:中断系统基本原理 Linux中断(interrupt)子系统之二:arch相关的硬件封装层 Linux中断(interrupt)子系统之三:中断流控处理 ...

  5. Yii2 基于RESTful架构的 advanced版API接口开发 配置、实现、测试

    环境配置: 开启服务器伪静态 本处以apache为例,查看apache的conf目录下httpd.conf,找到下面的代码 LoadModule rewrite_module modules/mod_ ...

  6. 257. Binary Tree Paths

    题目: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree ...

  7. 坑爹的Mysql

    本想尝试下如何使用Spring来管理Hibernate的事务,当配置好Spring的配置文件后,进行插入数据,结果报错了,错误是: Mysql Field * doesn't have a defau ...

  8. Java API —— ArrayList类 & Vector类 & LinkList类

    1.ArrayList类     1)ArrayList类概述         · 底层数据结构是数组,查询快,增删慢         · 线程不安全,效率高     2)ArrayList案例   ...

  9. QTP不能打开或者新建FunctionLibrary的解决方法

    今天打开QTP,然后打开function library的时候,qtp窗口右下角一直都是open...状态,怀疑是qtp与其他的软件冲突了. 解决方法: 直接执行QTP安装程序,然后选择修复QTP,问 ...

  10. cmd修改系统时间

    time 11:15:00  修改时间 date 2015/11/25  修改日期