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

解题报告:

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

2、状态转移方程:

  1. if(i>&&s3[i+j-]==s1[i-]&&dp[i-][j])
  2. dp[i][j]=;
  3. if(j>&&s3[i+j-]==s2[j-]&&dp[i][j-])
  4. dp[i][j]=;
  1. /*#include <iostream>
  2. #include <cstdio>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int dp[210][210];
  9. char s1[210],s2[210],s3[410];
  10. int t,n,len1,len2,i,j;
  11. scanf("%d",&n);
  12. for(t=1; t<=n; t++)
  13. {
  14. scanf("%s%s%s",s1,s2,s3);
  15. len1=strlen(s1);
  16. len2=strlen(s2);
  17. memset(dp,0,sizeof(dp));
  18. dp[0][0]=1;
  19. for(i=0; i<=len1; i++)
  20. {
  21. for(j=0; j<=len2; j++)
  22. {
  23. if(i>0 && s3[i+j-1]==s1[i-1] && dp[i-1][j])
  24. {
  25. dp[i][j]=1;
  26. }
  27. if(j>0 && s3[i+j-1]==s2[j-1] && dp[i][j-1])
  28. {
  29. dp[i][j]=1;
  30. }
  31. }
  32. }
  33. if(dp[len1][len2])
  34. {
  35. printf("Data set %d: yes\n",t);
  36. }
  37. else
  38. {
  39. printf("Data set %d: no\n",t);
  40. }
  41. }
  42. return 0;
  43. }
  44. */
  45.  
  46. #include <stdio.h>
  47. #include <string.h>
  48. #include <algorithm>
  49.  
  50. using namespace std;
  51.  
  52. int main()
  53. {
  54. int Case=;
  55. int t;
  56. scanf("%d",&t);
  57. while(t--)
  58. {
  59.  
  60. char s1[],s2[],s3[];
  61. scanf("%s%s%s",s1,s2,s3);
  62. int dp[][];///dp[i][j]表示s1前i个字符和s2前j个字符是否可以构成当前的一部分s3;
  63.  
  64. int len1,len2;
  65. len1=strlen(s1);
  66. len2=strlen(s2);
  67.  
  68. memset(dp,,sizeof(dp));
  69.  
  70. dp[][]=;
  71. for(int i=; i<=len1; i++)
  72. {
  73. for(int j=; j<=len2; j++)
  74. {
  75. if(i>&&s3[i+j-]==s1[i-]&&dp[i-][j])
  76. dp[i][j]=;
  77. if(j>&&s3[i+j-]==s2[j-]&&dp[i][j-])
  78. dp[i][j]=;
  79. }
  80. }
  81.  
  82. if(dp[len1][len2]==)
  83. printf("Data set %d: yes\n",Case++);
  84. else printf("Data set %d: no\n",Case++);
  85. }
  86. return ;
  87. }

类似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. 搭建element-ui Vue结构

    1.安装淘宝镜像 npm install cnpm -g --registry=https://registry.npm.taobao.org 2.安装webpack cnpm install web ...

  2. python3 repr()函数笔记

    a=[1,2,3,4]print(repr(a))print(type(repr(a)))for i in repr(a): print(i)#repr函数是将对象转换成string类型

  3. vue(3)IDE

    使用vscode,下载:https://code.visualstudio.com/Download 1.安装vscode 2.安装插件 方式一:https://marketplace.visuals ...

  4. 对称加密中的ECB模式&CBC模式

    ECB模式: CBC模式: 所有的迭代模式:

  5. cannot focus element解决方案

    If you enconter error "cannot focus element" when using Selenium+Python in Chrome to input ...

  6. sublime text2 for mac 实现json格式化

    问题描述: 网上拿下来的一大段json格式的字符串,放到sublime上格式化成json的标准格式 数据截图如下: 解决问题: 网络上搜了一下,大部分都是说要装pretty json插件 先来看看自己 ...

  7. 3d Max 2013安装失败怎样卸载3dsmax?错误提示某些产品无法安装

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

  8. Unity Screen Screen.currentResolution 当前分辨率

    The current screen resolution (Read Only). 当前屏幕的分辨率.(只读) If the player is running in window mode, th ...

  9. pta5-9 Huffman Codes (30分)

    5-9 Huffman Codes   (30分) In 1953, David A. Huffman published his paper "A Method for the Const ...

  10. SSH密钥登录原理

    Client 发送请求 login 请求 --> Server 接受请求 --> 根据 authorized_key 文件中的对应 Client 的 ip 地址的公钥对一串随机数进行加密 ...