类似LCS,构成目标单词(POJ2192)
题目链接: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)的更多相关文章
- 最长公共单词,类似LCS,(POJ2250)
题目链接:http://poj.org/problem?id=2250 解题报告: 1.状态转移方程: ; i<=len1; i++) { ; j<=len2; j++) { dp[i][ ...
- UVA - 10723 类似LCS
思路:dp(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串长度,cnt(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串的个数. 转移方程: if(s1[i] ...
- [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 ...
- [LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
- LUA实现单词替换功能
背景描述 编程或者文档处理过程, 经常遇到需要将一个单词修改为另外一个单词的情况, 例如 命名为 shall 修改 为 should. 使用工具实现, 则比较方便,不容易出错, 解放双手. 需求规格 ...
- LeetCode 79 Word Search(单词查找)
题目链接:https://leetcode.com/problems/word-search/#/description 给出一个二维字符表,并给出一个String类型的单词,查找该单词是否出现在该二 ...
- POJ-1080 Human Gene Functions---类似LCS
题目链接: https://cn.vjudge.net/problem/POJ-1080 题目大意: 给定两组序列,要你求出它们的最大相似度,每个字母与其他字母或自身和空格对应都有一个打分,求在这两个 ...
- leetcode 127 单词接龙
给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度.转换需遵循如下规则: 每次转换只能改变一个字母. 转换过程中的中 ...
- 正则表达式 整理(\w \s \d 点 贪婪匹配 非贪婪匹配 * + ? {} | [] ^ $ \b 单词边界 分组、re.findall()、re.split()、re.search()、re.match()、re.compile()、re.sub())
re.findall 匹配到正则表达式的字符,匹配到的每个字符存入一个列表,返回一个匹配到的所有字符列表 一. 匹配单个字符 import re # \w 匹配所有字母.数字.下划线 re.find ...
随机推荐
- TCP通讯模型简单示例
1. TCP通讯模型 2. 服务器端 ① 创建socket,用函数socket() ② 绑定IP地址.端口号等信息到socket上,用函数bind() ③ 设置允许的最大连接数,用函数listen() ...
- Ubuntu下安装Tomcate
1.官网下载安装包 http://tomcat.apache.org/download-80.cgi#8.5.9 2.解压 tar -zxvf apache-tomcat-.tar.gz 3.移动到/ ...
- 实用的vue插件大汇总
Vue是一个构建数据驱动的 web 界面的渐进式框架.Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件特别整理了常用的vue插件,来了个大汇总,方便查找使用,便于工作 ...
- Python开源库
某些情况下,pip install xxx找不到,而且在 官方库 也找不到. 那么 第三方库 就派上用场了.
- 命令行模式运行jmeter,主从方式运行jmeter
jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式: sh jmeter.sh -n -t my-script.jmx -R 10.6.5.31,10.6.5 ...
- Django重新整理
1.母版的继承 #base<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset ...
- Horizon
python manage.py compress python manage.py collectstatic {% extends "horizon/common/_modal_form ...
- Andrew Ng 的 Machine Learning 课程学习 (week3) Logistic Regression
这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...
- matlab 摘要
matlab中的向量与矩阵 如果定义一个A = [1, 2, 3]; 则A为一个行向量 但是A(:)返回的是一个列向量 关于函数的返回值 在function [a, b, c] = fit_quadr ...
- UVA 10462 —— Is There A Second Way Left?——————【最小生成树、kruskal、重边】
Nasa, being the most talented programmer of his time, can’t think things to be so simple. Recently a ...