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 ...
随机推荐
- firefox 安装flash插件
第一步下载并解压flash解压出一个文件:libflashplayer.so 和文件夹usr 第二步查找plugins其他程序或许也有这个文件夹所以先查找firefox在查找mozilla看在哪个文件 ...
- [C程序设计语言]第一部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Linux c 下使用getopt()函数
命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...
- 1----lua的环境搭建
本人使用的是LDT用来学习lua,原因是因为本人熟悉Eclipse的操作,并且安装方便 首先需要下载并配置JDK,也就是java的运行环境(以下为官网网址) http://www.oracle.com ...
- thinkphp 初始配置
他喵的,去做了个其他的模板,一段时间不碰tp,居然配置了好久 记录留备用 一.把下好的ThinkPHP放到根目录的文件夹下 ,例如www文件夹下 在www目录下新建文件夹admin和home 新建入口 ...
- Scrum Meeting---Four(2015-10-28)
今日已完成任务和明日要做的任务 姓名 今日已完成任务 今日时间 明日计划完成任务 估计用时 董元财 今日我完成了数据库表的设计以及创建 3h 进行Java Web工程的编写 4h 胡亚坤 用户之间的通 ...
- c++ IO的继承结构
#include <stdio.h> #include <iostream>//cin,cout #include <sstream>//ss transfer. ...
- Build Up Your Own Lightweight Workspace
写一段简单的批处理(.bat)放在自己建的workspace下. @set path=C:/Program Files/Java/jdk1.8.0_101/bin;%PATH%; //jdk的路径 @ ...
- IE浏览器GET传参后台乱码
ie里面 get传递的字符串 为 gb2312 ,后台用的是utf-8类型 所以用 POST传递字符串到后端 否则进行js参数转码 encodeURI(""); 后端解码
- Hbase之更新单条数据
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...