poj 1159(回文串dp)
来源:互联网 发布:电信网络电视多少钱 编辑:程序博客网 时间:2024/06/08 00:25
Palindrome
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 49315 Accepted: 16937
Description
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.
Input
Your program is to read from standard input. The first line contains one integer: the length of the input string N, 3 <= N <= 5000. The second line contains one string with length N. The string is formed from uppercase letters from 'A' to 'Z', lowercase letters from 'a' to 'z' and digits from '0' to '9'. Uppercase and lowercase letters are to be considered distinct.
Output
Your program is to write to standard output. The first line contains one integer, which is the desired minimal number.
Sample Input
5Ab3bd
Sample Output
2
Source
IOI 2000
题目很简单。
事实上回文串能用到的唯一性质就是,若str[i] ~ str[j] 是回文串, 则str[i+1] ~ str[j-1] 也是回文串。
好好这个性质可以解决大多数的回文串题目。
贡献了一次Timeout, 很久没看到了。
提交记录:
1、Timeout,是因为脑残多写了一层循环。注意斜着填表的时候,当i和interval确定的时候,j就是唯一确定的,不要再对j进行循环!
2、Accepted。
代码如下:
- poj 1159(回文串dp)
- poj 3280-回文串-DP
- poj 3280 Cheapest Palindrome ---(DP 回文串)
- (经典)POJ-3280 回文串DP
- poj 3280 dp回文
- 回文串 poj 1159
- POJ 1159 - Palindrome (DP 添加最少字符使s为回文串)
- ACM: 回文串 dp题 poj 1159 (滚动…
- POJ-1159 回文串 【LSC DP or +滚动数组省空间】
- poj 1159 回文串问题
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- hdu 1513 && poj 1159 线性dp回文字符串
- POJ 1159 最少添加几个字母构成回文 DP
- [区间dp 构建回文串] Cheapest Palindrome POJ
- uva 10453 回文串dp uva 10739 uva 11151最长回文串 poj 3280
- 1159--Palindrome(dp:回文串变形2)
- poj3280(回文串,DP)
- DP与回文串
- 给初中语文老师的书法字库软件
- MongoDB相关文章
- 机器学习II. Linear Regression with One Variable (Week 1) 单特征线性回归
- 判断你当前使用的shell程序
- HDU 1027 Ignatius and the Princess II
- poj 1159(回文串dp)
- ubuntu 常用问题解决方法
- POJ 1523 SPF 求割点及对应的连通分量数(入门题)
- C标准I/O库函数与无缓存的I/O函数
- usr/bin/ld: cannot find -lxxx的错误解决办法
- PHP做图书馆借书到期提醒与定时天气预报
- 黑马程序员:Map集合:Hashtable、HashMap、TreeMap介绍
- hdu 4427 Math Magic
- 计算程序运行的时间