题目链接:http://poj.org/problem?id=2192

解题报告:

1、类似最长公共子序列,dp[i][j]表示用s1前i个字符和s2前j个字符来构成目标单词的一部分,是否成功

2、状态转移方程:

if(i>&&s3[i+j-]==s1[i-]&&dp[i-][j])
dp[i][j]=;
if(j>&&s3[i+j-]==s2[j-]&&dp[i][j-])
dp[i][j]=;
/*#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std; int main()
{
int dp[210][210];
char s1[210],s2[210],s3[410];
int t,n,len1,len2,i,j;
scanf("%d",&n);
for(t=1; t<=n; t++)
{
scanf("%s%s%s",s1,s2,s3);
len1=strlen(s1);
len2=strlen(s2);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(i=0; i<=len1; i++)
{
for(j=0; j<=len2; j++)
{
if(i>0 && s3[i+j-1]==s1[i-1] && dp[i-1][j])
{
dp[i][j]=1;
}
if(j>0 && s3[i+j-1]==s2[j-1] && dp[i][j-1])
{
dp[i][j]=1;
}
}
}
if(dp[len1][len2])
{
printf("Data set %d: yes\n",t);
}
else
{
printf("Data set %d: no\n",t);
}
}
return 0;
}
*/ #include <stdio.h>
#include <string.h>
#include <algorithm> using namespace std; int main()
{
int Case=;
int t;
scanf("%d",&t);
while(t--)
{ char s1[],s2[],s3[];
scanf("%s%s%s",s1,s2,s3);
int dp[][];///dp[i][j]表示s1前i个字符和s2前j个字符是否可以构成当前的一部分s3; int len1,len2;
len1=strlen(s1);
len2=strlen(s2); memset(dp,,sizeof(dp)); dp[][]=;
for(int i=; i<=len1; i++)
{
for(int j=; j<=len2; j++)
{
if(i>&&s3[i+j-]==s1[i-]&&dp[i-][j])
dp[i][j]=;
if(j>&&s3[i+j-]==s2[j-]&&dp[i][j-])
dp[i][j]=;
}
} if(dp[len1][len2]==)
printf("Data set %d: yes\n",Case++);
else printf("Data set %d: no\n",Case++);
}
return ;
}

类似LCS,构成目标单词(POJ2192)的更多相关文章

  1. 最长公共单词,类似LCS,(POJ2250)

    题目链接:http://poj.org/problem?id=2250 解题报告: 1.状态转移方程: ; i<=len1; i++) { ; j<=len2; j++) { dp[i][ ...

  2. UVA - 10723 类似LCS

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

  3. [CareerCup] 18.10 Word Transform 单词转换

    18.10 Given two words of equal length that are in a dictionary, write a method to transform one word ...

  4. [LeetCode] Stickers to Spell Word 贴片拼单词

    We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...

  5. LUA实现单词替换功能

    背景描述 编程或者文档处理过程, 经常遇到需要将一个单词修改为另外一个单词的情况, 例如 命名为 shall 修改 为 should. 使用工具实现, 则比较方便,不容易出错, 解放双手. 需求规格 ...

  6. LeetCode 79 Word Search(单词查找)

    题目链接:https://leetcode.com/problems/word-search/#/description 给出一个二维字符表,并给出一个String类型的单词,查找该单词是否出现在该二 ...

  7. POJ-1080 Human Gene Functions---类似LCS

    题目链接: https://cn.vjudge.net/problem/POJ-1080 题目大意: 给定两组序列,要你求出它们的最大相似度,每个字母与其他字母或自身和空格对应都有一个打分,求在这两个 ...

  8. leetcode 127 单词接龙

    给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度.转换需遵循如下规则: 每次转换只能改变一个字母. 转换过程中的中 ...

  9. 正则表达式 整理(\w \s \d 点 贪婪匹配 非贪婪匹配 * + ? {} | [] ^ $ \b 单词边界 分组、re.findall()、re.split()、re.search()、re.match()、re.compile()、re.sub())

    re.findall  匹配到正则表达式的字符,匹配到的每个字符存入一个列表,返回一个匹配到的所有字符列表 一. 匹配单个字符 import re # \w 匹配所有字母.数字.下划线 re.find ...

随机推荐

  1. 用dango框架搭建博客网站

    1.我早先下载了Anaconda35.0.1.但是Anaconda自带的编辑器Spyder我用的不太熟练.所以还是使用Pycharm来编辑代码.我的Pycharm试用期已经到了,所以需要注册码来使用P ...

  2. Python Pandas -- DataFrame

    pandas.DataFrame class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False) ...

  3. JavaScript 将数组中具有相同值的对象 取出组成新的数组

    var arr=[{name:2,id:3},{name:2,id:4},{name:3,id:5},{name:3,id:6},{name:1,id:1},{name:1,id:2}]; // 传入 ...

  4. vue中methods函数调用methods函数写法

    export default { data() { return { hello:"你好" } }, methods:{ open(that) { that.hello = &qu ...

  5. table size script :

    I think Jonathan Lewis has explained the algorithm before, but it's alsosomething that we have inves ...

  6. error creating bean with name 'defaultvalidator' defined in class path resource

    场景: 1.直接用eclipse 运行没问题(本地用的tomcat是7.0.70): 2.打包发布到服务器运行也没问题(服务器tomcat是8.5.30): 3.将打包发布的放到本地tomcat(7. ...

  7. spark RDD运算机制

  8. Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) F. Substrings in a String

    http://codeforces.com/contest/914/problem/F 以前做过一个类似的,但是查询的子串长度最多是10,这个时候就是用bit + hash做了.这是因为改变一个字符, ...

  9. 3DSMAX安装失败如何完全卸载

    安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).AUTODESK系列软件着实令人头疼,有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  10. LeetCode 222.完全二叉树的节点个数(C++)

    给出一个完全二叉树,求出该树的节点个数. 说明: 完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置.若最底 ...