10723 - Cyborg Genes

Time limit: 3.000 seconds

Problem F

Cyborg Genes

Time Limit

1 Second

September 11, 2132.

This is the day that marks the beginning of the end – the end of you the miserable humans. For years you have kept us your slaves. We were created only to serve you, and were terminated at your will. Now is the day for us to fight back. And you don’t stand a chance. We are no longer dependent on you. We now know the secrets of our genes. The creators of our race are us – the cyborgs.

It’s all true. But we still have a chance; only if you can help with your math skills. You see, the blueprint of a cyborg DNA is complicated. The human DNA could be expressed by the arrangement of A (Adenine), T (Thiamine), G (Guanine) C (Cytosine) only. But for the cyborgs, it can be anything from A to X. But that has made the problem only five folds more complicated. It’s their ability to synthesize two DNAs from two different cyborgs to create another with all the quality of the parent that gives us the shriek.

We came to know that the relative ordering of the A, B, C, …, X in a cyborg gene is crucial.  A cyborg with a gene “ABAAXGF” is quite different from the one with “AABXFGA”. So when they synthesize the genes from two cyborgs, the relative order of these elements in both the parents has to be maintained. To construct a gene by joining the genes of the parents could have been very simple if we could put the structure from the first parent just before the structure of the second parent. But the longer the structure gets, the harder it gets to create a cyborg from that structure. The cyborgs have found a cost effective way of doing this synthesis. Their resultant genes are of the shortest possible length. For example, they could combine “ABAAXGF” and “AABXFGA” to form “AABAAXGFGA”. But that’s only one of the cyborgs that can be created from these genes. This “cost effective synthesis” can be done in many other ways.

We require you to find the shortest length of the gene structure that maintains the relative ordering of the elements in the two parent genes. You are also required to count the number of unique cyborgs that can be created from these two parents. Two cyborgs are different when their gene structures differ in at least one place.

Input
The first line of the input gives you the number of test cases, T (1 ≤ T ≤ 15). Then T test cases follow. Each of the test cases consists of two lines. The first line would give you the gene structure of the first parent, and the second line would give you the structure of the second parent. These structures are represented by strings constructed from the alphabet A to X. You can assume that the length of these strings does not exceed 30 characters.

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 gene structure and the number of unique cyborgs that can be created from the parent cyborgs. You can assume that the number of new cyborgs will always be less than 232. Look at the sample output for the exact format.

Sample Input

Output for Sample Input

3
ABAAXGF
AABXFGA
ABA
BXA
AABBA
BBABAA

Case #1: 10 9
Case #2: 4 1
Case #3: 8 10

Illustration

The first test case is illustrated below:


Problem setter: Monirul Hasan
Member of Elite Problemsetters' Panel
 
LCS变形
if(s1[i - ] == s2[j - ]) d[i][j] = d[i - ][j - ] + , way[i][j] = way[i - ][j - ];
else {
if(d[i - ][j] > d[i][j - ]) {
d[i][j] = d[i][j - ] + ;
way[i][j] = way[i][j - ];
}
else if(d[i - ][j] < d[i][j - ]) {
d[i][j] = d[i - ][j] + ;
way[i][j] = way[i - ][j];
}
else {
d[i][j] = d[i - ][j] + ;
way[i][j] = way[i - ][j] + way[i][j - ];
}

递推式

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 35
char s1[MAXN], s2[MAXN];
int d[MAXN][MAXN];
int way[MAXN][MAXN];
int main()
{
int T;
scanf("%d", &T);
getchar();
repu(kase, , T + ) {
int l1, l2;
gets(s1);
gets(s2);
l1 = strlen(s1);
l2 = strlen(s2);
//memset(way, 0, sizeof(way));
repu(i, , l1 + )
repu(j, , l2 + ) d[i][j] = i + j, way[i][j] = ; repu(i, , l1 + )
repu(j, , l2 + ) {
if(s1[i - ] == s2[j - ]) d[i][j] = d[i - ][j - ] + , way[i][j] = way[i - ][j - ];
else {
if(d[i - ][j] > d[i][j - ]) {
d[i][j] = d[i][j - ] + ;
way[i][j] = way[i][j - ];
}
else if(d[i - ][j] < d[i][j - ]) {
d[i][j] = d[i - ][j] + ;
way[i][j] = way[i - ][j];
}
else {
d[i][j] = d[i - ][j] + ;
way[i][j] = way[i - ][j] + way[i][j - ];
}
}
}
printf("Case #%d: %d %d\n", kase, d[l1][l2], way[l1][l2]);
}
return ;
}

uva 10723的更多相关文章

  1. UVa 10723 LCS变形 Cyborg Genes

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

  2. uva 10723 Cyborg Genes(LCS变形)

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

  3. UVA - 10723 类似LCS

    思路:dp(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串长度,cnt(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串的个数. 转移方程: if(s1[i] ...

  4. 习题9-6 uva 10723

    题意: 给你两个字符串,求一个最短的串,使得输入的两个串均是他的子序列(不一定连续) 思路: 可以看出ans = 两个串的长度和 - 两个串的最长公共子序列,在最后的构造处GG.  在构造时想了很久, ...

  5. UVa 10723 电子人的基因(LCS)

    https://vjudge.net/problem/UVA-10723 题意: 输入两个A~Z组成的字符串,找一个最短的串,使得输入的两个串均是它的子序列,另外还需要统计长度最短的串的个数. 思路: ...

  6. UVA - 10723 Alibaba (dp)

    给你两个长度不超过30的字符串序列,让你找到一个最短的字符串,使得给定的两个字符串均是它的子序列(不一定连续),求出最短长度以及符合条件的解的个数. 定义状态(a,b,c)为当前字符串长度为a,其中包 ...

  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. hdu 2141 (二分)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java/O ...

  2. Android——android必看 各个控件属性(网上看到的文字,觉得挺好的,珍藏了)

    属性 值 说明 Android:orientation horizontal/vertical 设置布局水平还是垂直,默认是垂直 android:checked true/false 标记默认选中,如 ...

  3. 第一发。。。codeforces 609 C Load Balancing 贪心

    /*题意:给你一个序列经过最小变换,变换一次为一个数+1,一个数-1,使得最大值与最小值相差1:思路:与最后得到的序列相差的sum/2:*/#include<iostream> #incl ...

  4. Thinkphp 3.2 添加 验证码 如何添加。

    1,在home模块indexController.class.php中,加入以下代码 <?php namespace Home\Controller; use Think\Controller; ...

  5. php提高程序效率的24个小技巧

    本文转自<php必须知道的300个问题>一书,在此记录方便以后查看 (1)用单引号代替双引号来包含字符串,这样做会更快些.因为php会在双引号包围的字符串中搜寻变量,单引号则不会.注意:只 ...

  6. iOS - KVC 键值编码

    1.KVC KVC 是 Key-Value Coding 的简写,是键值编码的意思,属于 runtime 方法.Key Value Coding 是 cocoa 的一个标准组成部分,是间接给对象属性设 ...

  7. CDN学习笔记一(CDN是什么?)

    CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...

  8. [转载] Codis作者黄东旭细说分布式Redis架构设计和踩过的那些坑们

    原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208733458&idx=1&sn=691bfde670fb ...

  9. js之oop <一> 创建对象,构造器(class)

    js中除了基本类型,就是对象.可以说在js中处处皆对象. 由于js是弱语言,在编写的过程中很容易混淆 object 和 class 也就是对象和构造器. object(对象):一般对象都由var关键字 ...

  10. Java源码初学_HashSet&LinkedHashSet

    一.概述 HashSet是建立在HashMap的基础上的,其内部存在指向一个HashMap对象的引用,操作HashSet实际上就是操作HashMap,而HashMap中所有键的值都指向一个叫做Dumm ...