题目链接: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. 检测客户pc电脑端VC++环境并安装

    CefSharp 是一个非常不错的cef封装.但它依赖于VC++环境. 具体如下: Branch CEF Version VC++ Version .Net Version Status master ...

  2. 1.搭建JavaEE开发环境

    1.Web应用介绍: 2.Servlet简介 3.JSP简介 4.Servlet容器 Web服务器有静态资源和动态页面,静态资源是*.html(文件系统),动态页面是Servlet容器. 5.Tomc ...

  3. VS 2017与 Docker

    https://www.cnblogs.com/rufus-hua/p/6742836.html 参考 1 基于VS2017的Docker Support体检ASP.NET Core站点的Docker ...

  4. python Gensim库建立word2vec参数说明

    from gensim.models import word2vec model = word2vec.Word2Vec(sentences, size=80, window=10,workers=6 ...

  5. hibernate打印sql日志及参数

    #log4j.properties log4j.rootLogger=info, CA# ConsoleAppenderlog4j.appender.CA=org.apache.log4j.Conso ...

  6. Java基础11-数组

    1.使用数组步骤: (1)声明数组 int[] a; (2)分配空间 a=new int[5]; (3)赋值 a[0]=1;  int类型数组如果没有赋值,默认值为0,String类型数组默认为nul ...

  7. Trace Logging Level

    Trace In functions which support this level, details every parameter and operation to help diagnose ...

  8. LeetCode 62.不同路径(C++)

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”). 问总共有多 ...

  9. ThinkPHP 统计数据(数字字段)更新 setInc 与 setDec 方法

    ThinkPHP 统计数据更新 ThinkPHP 内置了对统计数据(数字字段)的更新方法: setInc():将数字字段值增加 setDec():将数字字段值减少 setInc() ThinkPHP ...

  10. SWIG 和 Python——c/c++与脚本交互

    C 和 C++ 被公认为(理当如此)创建高性能代码的首选平台.对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface ...