poj 2192 (DP)
这个题题目意思是给你三个字符串str1,str2,str3.将str3从左自右扫描,去匹配str1和str2中的元素,不可重复,若存在一种匹配方法使得str1和str2都被匹配完全了,则输出yes,否则no
用布尔变量dp[i][j]表示组成一个字符串用了第一个字符串的i个字符,用了第二个字符串的j个字符,那么题目所要求的就是dp[len1][len2].
// File Name: 2192.cpp
// Author: Missa_Chen
// Created Time: 2013年07月08日 星期一 09时09分47秒 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <vector>
#include <time.h> using namespace std; #define LL long long
const int maxn = 2e2 + ;
bool solve(string s1, string s2, string s)
{
bool dp[maxn][maxn] = {};
for (int i = ; i <= s1.size(); ++i)
if (s1[i - ] == s[i - ])
dp[i][] = ;
for (int i = ; i <= s2.size(); ++i)
if (s2[i - ] == s[i - ])
dp[][i] = ;
for (int i = ; i <= s1.size(); ++i)
for (int j = ; j <= s2.size(); ++j)
{
if ((s1[i - ] == s[i + j - ] && dp[i - ][j]) ||
(s2[j - ] == s[i + j - ] && dp[i][j - ]))
dp[i][j] = ;
}
return dp[s1.size()][s2.size()];
}
int main()
{
int T;
cin >> T;
for (int i = ; i <= T; ++i)
{
string s1, s2, s;
cin >> s1 >> s2 >> s;
cout << "Data set "<< i <<": ";
if (solve(s1, s2, s)) cout <<"yes" << endl;
else cout << "no" << endl;
}
return ;
}
poj 2192 (DP)的更多相关文章
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- poj 2192 Zipper(区间dp)
题目链接:http://poj.org/problem?id=2192 思路分析:该问题可以看做dp问题,同时也可以使用dfs搜索求解,这里使用dp解法: 设字符串StrA[0, 1, …, n]和S ...
- HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)
题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然 ...
- POJ 2192 【DP】
题意: 给三个字符串,判断前两个在相对顺序不变的情况下是否可以组成第三个字符串. 思路: 先说屌丝: dp[i][j]代表1串的前i个和2串的前j个字符在3串的前i+j个字符中最多能够组合出几个字符. ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- poj 1609 dp
题目链接:http://poj.org/problem?id=1609 #include <cstdio> #include <cstring> #include <io ...
- POJ 1037 DP
题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...
- Jury Compromise POJ - 1015 dp (标答有误)背包思想
题意:从 n个人里面找到m个人 每个人有两个值 d p 满足在abs(sum(d)-sum(p)) 最小的前提下sum(d)+sum(p)最大 思路:dp[i][j] i个人中 和 ...
随机推荐
- 基于jQuery很牛X的批量上传插件
上传功能应该是每个网站必备的工具之一,因此出现了出现了很多各式各样的上传插件! 本文基于个人经验和使用从插件的:交互体验,易用性,文档,美观度出发,为大家推荐三款很NX的批量上传插件! 下面三款插件的 ...
- Ambient Occlusion
一般在光照模型中,ambient light的计算方法为:A = l * m,其中l表示表面接收到的来自光源的ambient light的总量,而m表示表面接收到ambient light后,反射和吸 ...
- NODEjs常见错误检查
一.没有添加对uncaughtException异常的捕捉处理,最起码也要在其中写个日志记录错误,然后可以调用 process.exit(1); 退出进程. 二.处理函数的回调函数检查,经常忘记在回调 ...
- GCD常用方法
1.延迟操作 2.一次性代码 3.队列组 /** * 延迟执行 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC ...
- EF框架批量更新
var customers = db.Customers.Where(c => c.name=='小明'); foreach (var customer in customers) { cust ...
- HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数
GTW likes function Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...
- 搭建turnserver
参考文件: http://blog.csdn.net/kl222/article/details/20145423 为什么要搭建TURN服务器? 因为我们编写的sip客户端再和南瑞的sip服务器进行通 ...
- WordPress定位当前使用模版
把下面代码插入到wp-includes/template-loader.php,66行 if($_GET[tpl]=='die'){ die($template); } 浏览任意页面,在网址后加上&a ...
- SSIS ->> Control Flow And Data Flow
In the Control Flow, the task is the smallest unit of work, and a task requires completion (success, ...
- mac 下tomcat启动报错 unknown host
解决方法:sudo scutil --set HostName localhost