【习题 6-3 UVA - 536】 Tree Recovery
2024-08-31 20:04:14
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
递归题
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
string s1, s2;
int n, idx;
int g[N][2];
int dfs(int l, int r) {
int temp = l;
for (int i = l; i <= r; i++) {
if (s2[i] == s1[idx]) {
temp = i;
}
}
idx++;
if (l <= temp - 1) {
g[(int)s2[temp]][0] = dfs(l, temp-1);
}
if (temp + 1 <= r) {
g[(int)s2[temp]][1] = dfs(temp + 1, r);
}
return s2[temp];
}
void dfs2(int x) {
if (g[x][0]) {
dfs2(g[x][0]);
}
if (g[x][1]) {
dfs2(g[x][1]);
}
cout << (char)x;
}
int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0), cin.tie(0);
while (cin >> s1 >> s2) {
memset(g, 0, sizeof g);
n = s1.size();
idx = 0;
dfs2(dfs(0, n - 1));
cout << endl;
}
return 0;
}
最新文章
- sudo:有效用户 ID 不是 0,sudo 属于 root 并设置了 setuid 位吗
- ReWriteDateControll
- 自定义cell侧滑删除
- 黑马程序员-循环引用问题和weak
- 学习使用 jQuery &; CSS3 制作照片堆栈效果
- 活学活用,webapi HTTPBasicAuthorize搭建小型云应用的实践
- Python超简单的HTTP服务器
- ElasticSearch使用IK中文分词---安装步骤记录
- spring html特殊字符操作
- EJB3Persistence开发手册-原生SQL查询(NativeSQL)
- eclipse/myeclipse选中编辑区域文件,Package Explorer定位文件所在项目及目录
- 8、第八次课jquery第一节20151006
- UML_行为图
- poj 2114 Boatherds 树的分治
- [LeetCode] Two Sum IV - Input is a BST 两数之和之四 - 输入是二叉搜索树
- java客户端调用webService
- mybatis中传入String类型参数的问题
- SQL中EXPLAIN命令详解
- JS常用各种正则表达式(汇总)
- Java动态生成类以及动态添加属性