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 ...
随机推荐
- Genymotion加载so出错解决方案
通过网上所搜得出结论: Genymotion是x86的架构,而我们的so库是arm架构的 解决:安装Genymotion-ARM-Translation.zip 1.下载:http://pan.bai ...
- [Hibernate]dynamic-insert和dynamic-update属性
这二个属性默认情况均为false,你可以通过以下二种方式进行配置使用: 1.Annotation @Entity @Table(name = "stock_transaction" ...
- SQO2008配置管理工具服务显示远程过程调用失败
前两天,装了VS2012后,打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示:(如图) 卸载了一个叫"Microsoft SQL Server 2012Local ...
- floodlight 中两个互相矛盾的地方
floodlight中,添加防火墙规则,0表示最高优先级,数字越大,优先级越低;但是在StaticFlowPusher中写flow的时候,0表示最低优先级,数字越大,优先级越高,32767为最高. f ...
- oracle触发器详解(转)
触发器是许多关系数据库系统都提供的一项技术.在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处理过程的PL/SQL块. 8.1 触发器类型 触发器在数据库里以独立的对象存储,它与存储过 ...
- hdu 1002 java 大数相加
package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...
- ASP.NET并发处理
http://blog.csdn.net/hliq5399/article/details/6280288
- NSArray 数组排序
//方法1,使用自带的比较器 //compare是数组自带的比较方法 NSArray *array=[NSArray arrayWithObjects:@"3",@"1& ...
- 如何写出优秀的研究论文 Chapter 1. How to Write an A+ Research Paper
This Chapter outlines the logical steps to writing a good research paper. To achieve supreme excelle ...
- IOS地图及定位使用
1.定位 定位使用CoreLocation库,引入CoreLocation/CoreLocation.创建CLLocationManager对象,使用startUpdatingLocation方法开始 ...