uva 10723
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 |
Case #1: 10 9 |
Illustration
The first test case is illustrated below:

Member of Elite Problemsetters' Panel
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的更多相关文章
- 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 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...
- UVA - 10723 类似LCS
思路:dp(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串长度,cnt(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串的个数. 转移方程: if(s1[i] ...
- 习题9-6 uva 10723
题意: 给你两个字符串,求一个最短的串,使得输入的两个串均是他的子序列(不一定连续) 思路: 可以看出ans = 两个串的长度和 - 两个串的最长公共子序列,在最后的构造处GG. 在构造时想了很久, ...
- UVa 10723 电子人的基因(LCS)
https://vjudge.net/problem/UVA-10723 题意: 输入两个A~Z组成的字符串,找一个最短的串,使得输入的两个串均是它的子序列,另外还需要统计长度最短的串的个数. 思路: ...
- UVA - 10723 Alibaba (dp)
给你两个长度不超过30的字符串序列,让你找到一个最短的字符串,使得给定的两个字符串均是它的子序列(不一定连续),求出最短长度以及符合条件的解的个数. 定义状态(a,b,c)为当前字符串长度为a,其中包 ...
- 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 ...
随机推荐
- php工具 phpstorm 的快捷键 的使用(待添加
参考网址:http://www.cnblogs.com/jikey/p/3491798.html 1. ctrl+tab 键,可以切换各个选项卡 页面 2. shift+enter 键,无论光标在本行 ...
- iOS - Photo Album 图片/相册管理
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImagePickerController : UINavigationController <NSCod ...
- 转:随机函数 C++中rand()函数的用法
转自:http://blog.163.com/wujiaxing009@126/blog/static/719883992011113011359154/ 一.C++中不能使用random()函数 ...
- 转:为什么C++中空类和空结构体大小为1?
参考:http://www.spongeliu.com/260.html 为什么C++中空类和空结构体大小为1? On November 17, 2010, in C语言, 语言学习, by spon ...
- D3.js 简介和安装
一.What´s D3.js D3.js是一种数据操作类型的javascript库(也可视其为插件):结合HTML,SVG和CSS,D3可以图形化的,生动的展现数据. D3 的全称是(Data-Dri ...
- JavaScript的事件对象_概述/this
JavaScript 事件的一个重要方面是它们拥有一些相对一致的特点,可以给你的开发提供更多的强大功能. 最方便和强大的就是事件对象,他们可以帮你处理鼠标事件和键盘敲击方面的情况,此外还可以修改一般事 ...
- hdu_3555 bomb
数位动态规划 数位动态规划是求解一个大区间[L, R]中间满足条件Q的所有数字的个数(或者和,或其他)的一种方法.它通过分析每一位上的数字,一般用 dp[len][digit][...] 来表 ...
- PHP 安全相关 简单知识
概要: 1.php一些安全配置 (1)关闭php提示错误功能 (2)关闭一些“坏功能” (3)严格配置文件权限. 2.严格的数据验证,你的用户不全是“好”人 2.1为了确保程序的安全性,健壮性,数据验 ...
- PHP5中PDO的简单使用
PHP5中PDO的简单使用 标签: php数据库mysql扩展extensionexception 2012-05-06 10:27 27753人阅读 评论(0) 收藏 举报 分类: PHP(6) ...
- Linux下软件安装方法即路径设置
Linux下软件安装方法即路径设置 http://www.cnblogs.com/edward259/archive/2010/07/02/1770066.html