poj1159(回文字串)
来源:互联网 发布:手机怎样看淘宝的积分 编辑:程序博客网 时间:2024/05/01 16:59
Palindrome
Time Limit: 3000MSMemory Limit: 65536KTotal Submissions: 41514Accepted: 14146
Description
A palindrome is a symmetricalstring, that is, a string read identically from left to right aswell as from right to left. You are to write a program which, givena string, determines the minimal number of characters to beinserted into the string in order to obtain a palindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can betransformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However,inserting fewer than 2 characters does not produce apalindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can betransformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However,inserting fewer than 2 characters does not produce apalindrome.
Input
Your program is to read fromstandard input. The first line contains one integer: the length ofthe input string N, 3 <= N <= 5000.The second line contains one string with length N. The string isformed from uppercase letters from 'A' to 'Z', lowercase lettersfrom 'a' to 'z' and digits from '0' to '9'. Uppercase and lowercaseletters are to be considered distinct.
Output
Your program is to write tostandard output. The first line contains one integer, which is thedesired minimal number.
Sample Input
5Ab3bd
Sample Output
2
Source
IOI 2000
#include<stdio.h>
#include<string.h>
short int d[5010][5010];//如果不用short,会超内存
char s[5010];
int min(int x,int y)
{
}
int main()
{
}
这题还可以用滚动数组做(很多大牛们都是这样做的)
参考资料http://archive.cnblogs.com/a/2155738/
下面是我照这别人代码敲的。。输入格式很容易错哦。。WA了好多次了。。就是scanf()这边。。还是建议用cin>>s1吧。。。下面代码是WA的。。把输入格式改一下就A了。。
#include<string.h>
#define max 5005
char s1[max],s2[max];
int maxlen[2][max];
int main()
{
}
- poj1159(回文字串)
- poj1159(回文串)
- POJ1159:Palindrome(回文数)
- poj1159(Palindrome+回文串)
- poj1159(回文串+LCS+滚动数组)
- POJ1159回文字符串(DP+滚动数组)
- 添字成回文词 POJ1159
- 回文串 poj1159
- POJ1159 Palindrome(dp加最少字母构成回文字符串)
- 回文字串
- Longest Palindromic Substring(最长回文字串)
- 后缀数组(最长回文字串)ural1297
- 最长回文字串(mancher算法)
- Palindrome(补全回文串+最长公共子序列的应用)hdu1513+poj1159+动态规划
- poj1159——Palindrome(组成回文串的最少字符数,dp)
- POJ1159 Palindrome(最大回文串长度)
- poj1159 Palindrome 【最长回文子序列】
- 最长回文字串
- 七、线程调度优先级和关联性
- poj1700andpoj3404
- 合唱队列
- (DP)最大子段和问题分析和总结(…
- poj1050(DP)
- poj1159(回文字串)
- (挑战编程_7_1)Light, more light
- poj1163(DP)and3176(DP)多串的…
- poj2533(DP)(与杭电1257一模一…
- jq-手机-图片大小
- 木兰花令——纳兰性德
- HDOJ2602(DP0-1背包)
- poj1742andHDOJ2844(DP多重背包)
- poj1276(DP多重背包)