avatar
s*d
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: saiad (happy), 信区: JobHunting
标 题: 一道C++面试题
发信站: BBS 未名空间站 (Thu Jan 4 19:52:27 2007), 转信
A palindrome is a String that is spelled the same forward and backwards.
Given a String base that may or may not be a palindrome, we can always force
base to be a palindrome by adding letters to it. For example, given the
word "RACE", we could add the letters "CAR" to its back to get "RACECAR" (
quotes for clarity only). But, we are not restricted to adding letters at
the ba
avatar
O*d
2
这个和C++有什么关系?
avatar
q*g
3
可能是用c++写出code吧

【在 O*******d 的大作中提到】
: 这个和C++有什么关系?
avatar
r*g
4
DP
avatar
c*z
5
hi, can you give some more detail on how to use dp
are you going to a fixe a point as pivot and match th strings on both sides
using edit distance?

【在 r********g 的大作中提到】
: DP
avatar
f*r
6
post some analysis from topcoder
A key observation is that, to make the shortest possible palindrome out of
base, you should never add letters to both the front and back of the string.
If you were to do so, then you could make an even shorter palindrome by
removing the first and last characters that you added. Therefore, the
shortest palindrome that you can make out of base must either start with the
first letter of base or end with the last letter of base (or both, if the
first and last letters

【在 c*****z 的大作中提到】
: hi, can you give some more detail on how to use dp
: are you going to a fixe a point as pivot and match th strings on both sides
: using edit distance?

avatar
f*i
7
Job Hunting版给出的breadth-first-search的方法更好。
top-coder的递归解法本质上是depth-first-search,遍历搜索空间所有的节点,
再比较叶子节点的高度,取最小值。而breadth-first-search可以直接找到高度
最小的叶子节点,而避免遍历整个搜索空间。
另外,topcoder解答中的memoization,在breadth-first-search里面也可以很容易
的实现。

of
string.
the

【在 f********r 的大作中提到】
: post some analysis from topcoder
: A key observation is that, to make the shortest possible palindrome out of
: base, you should never add letters to both the front and back of the string.
: If you were to do so, then you could make an even shorter palindrome by
: removing the first and last characters that you added. Therefore, the
: shortest palindrome that you can make out of base must either start with the
: first letter of base or end with the last letter of base (or both, if the
: first and last letters

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。