题目链接: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. AsyncLocal 与 ThreadLocal ThreadStatic特性简介

    AsyncLocal 与 ThreadLocal [.NET深呼吸]基于异步上下文的本地变量(AsyncLocal) https://www.cnblogs.com/tcjiaan/p/5007737 ...

  2. Hibernate通过自编写Sql修改

    @Override public void updateTemMsg(String ticket,String time) { String sql="UPDATE INTER_TEMPTO ...

  3. linux进程间的通信之 共享内存

    一.共享内存介绍 共享内存是三个IPC(Inter-Process Communication)机制中的一个. 它允许两个不相关的进程访问同一个逻辑内存. 共享内存是在两个正在进行的进程之间传递数据的 ...

  4. fuser解决The requested resource is busy

    AIX 下出现umount busy | 处理  2011-08-17 17:22:57|  分类: AIX|字号 订阅如果一个文件系统打开了一个文件,那么必须在卸载之前将该文件关闭.例如:# umo ...

  5. css实现高度垂直居中

    1:单行文字垂直居中: 如果一个容器中只有一行文字的话,定义height(高度)和 line-height(行高)相等即可. 如:<div style="height:25px;lin ...

  6. mysql中操作符LIKE与通配符%的使用

    mysql中通配符%用来通配其他字符,操作符LIKE用来查询字段中存在相同的字符 SELECT t.userId,t.cellphone,t.idNo,t.* FROM t_person t WHER ...

  7. 变量&数据类型

    php标记:四种php标记       1.<?php echo 'hello';?>       2.<? echo 'hello'; ?> //短标记       3.&l ...

  8. [转]Java内存溢出详解及解决方案

    原文地址:http://blog.csdn.net/xianmiao2009/article/details/49254391 内存溢出与数据库锁表的问题,可以说是开发人员的噩梦,一般的程序异常,总是 ...

  9. 拿到返回值,Callable示例

  10. pdf word excel ppt 在线预览方案收集

    https://www.idocv.com/docs.html http://www.cnblogs.com/wolf-sun/p/3569960.html http://coolwanglu.git ...