类似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 ...
随机推荐
- 搭建element-ui Vue结构
1.安装淘宝镜像 npm install cnpm -g --registry=https://registry.npm.taobao.org 2.安装webpack cnpm install web ...
- python3 repr()函数笔记
a=[1,2,3,4]print(repr(a))print(type(repr(a)))for i in repr(a): print(i)#repr函数是将对象转换成string类型
- vue(3)IDE
使用vscode,下载:https://code.visualstudio.com/Download 1.安装vscode 2.安装插件 方式一:https://marketplace.visuals ...
- 对称加密中的ECB模式&CBC模式
ECB模式: CBC模式: 所有的迭代模式:
- cannot focus element解决方案
If you enconter error "cannot focus element" when using Selenium+Python in Chrome to input ...
- sublime text2 for mac 实现json格式化
问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...
- 3d Max 2013安装失败怎样卸载3dsmax?错误提示某些产品无法安装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- Unity Screen Screen.currentResolution 当前分辨率
The current screen resolution (Read Only). 当前屏幕的分辨率.(只读) If the player is running in window mode, th ...
- pta5-9 Huffman Codes (30分)
5-9 Huffman Codes (30分) In 1953, David A. Huffman published his paper "A Method for the Const ...
- SSH密钥登录原理
Client 发送请求 login 请求 --> Server 接受请求 --> 根据 authorized_key 文件中的对应 Client 的 ip 地址的公钥对一串随机数进行加密 ...