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 ...
随机推荐
- HDU 1164 Eddy's research I
题目链接 题意 : 给你一个数,让你用它的素数质因子表示出来. 思路 : 先打一下表,因为会有重复的质因子,所以从大到小开始找,并且找到一个之后不能就接着往下找,要再找一遍这个数. #include ...
- POJ1789Truck History
题意 : 说实话,题意我没看懂,后来让人给我讲的样例..... 4 aaaaaaa baaaaaa abaaaaa aabaaaa 0 这个样例的话,就是输入n下面n行,每行7个字母,让你依次选两行进 ...
- ios 关于StoryBoard 的简易使用说明
ios 关于StoryBoard 的简易使用说明 http://www.tuicool.com/articles/FNRruy
- Java Socket编程readLine返回null,read返回-1的条件
客户端正常关闭socket的时候,服务器端的readLine()方法会返回null,或者read()方法会返回-1
- 小米2S 连接Ubuntu Android Studio
1. 首先打开手机上的开发者选项,USB调试.拨号:*#*#717717#*#* ,手机会以Toast形式出现“……enable”字样.再次拨号可disable. 2. Ubuntu安装mtpfs: ...
- java socket知识点
3.用线程池实现TCP服务器端时,首先创建一个ServerSocket实例,然后创建N个线程,每个线程反复循环,从(共享的)ServerSocket实例接收客户端连接.当多个线程同时调用一个Serve ...
- Photoshop CS4序列号过期的问题
1)在网络上搜寻一些PS CS4序列号: 如1330-1221-6824-4838-0308-6823,1330-1283-7461-4574-7002-2504,1330-1795-2880-537 ...
- HDU 4686 Arc of Dream(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 思路: #include <iostream>#include <cs ...
- Generic Data Access Layer泛型的数据访问层
http://www.codeproject.com/Articles/630277/Generic-Data-Access-Layer-GDA-Part-I http://www.codeproje ...
- timus1004 最小环()Floyd 算法
通过别人的数据搞了好久才成功,果然还是不够成熟 做题目还是算法不能融会贯通 大意即找出图中至少3个顶点的环,且将环中点按顺序输出 用floyd算法求最小环 因为floyd算法求最短路径是通过中间量k的 ...