51nod 1092 回文字符串
来源:互联网 发布:linux安装pip 编辑:程序博客网 时间:2024/05/12 14:51
题目链接:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1092
题解:
本题要求的是求最小添加的数,那么可以进行反向的思考,直接算最大的公共长度,然后用总长度-最的公共长度之后,就是答案了。
代码:
#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm> using namespace std;const int maxn =1000+10;#define met(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3fstring s1,s2;int dp[maxn][maxn];int main(){ while(cin>>s1) { met(dp,0); s2=s1; reverse(s2.begin(),s2.end()); for(int i=0;i<s1.length();i++) for(int j=0;j<s2.length();j++) { int cnt=0; if(s1[i]==s2[j]) cnt=1; dp[i+1][j+1]=max(dp[i][j]+cnt,max(dp[i][j+1],dp[i+1][j])); } int ans=s1.length()-dp[s1.length()][s2.length()]; cout<<ans<<endl; }}
0 0
- 【51nod】1092 回文字符串
- 1092 回文字符串(51nod)
- 51 nod 1092 回文字符串
- 51nod 1092 回文字符串
- 51nod 1092 回文字符串
- 51nod-【1092 回文字符串】
- 51nod 1092 回文字符串
- 51Nod 1092 回文字符串
- 51nod 1092 回文字符串
- 51Nod 1092 回文字符串
- 51nod 1092 回文字符串
- 51nod 1092 回文字符串
- 51nod 1092 回文字符串 (LCS_DP)
- 51nod 1092 回文字符串 dp问题
- 51Nod-1092-回文字符串
- 【51Nod】1092 - 回文字符串(LCS)
- LCS-51NOD-1092 回文字符串
- 51nod 1092 回文字符串(区间dp)
- 中文词语自动纠错_编辑距离
- 求多组数两个数的相加
- 卡片游戏
- 无聊了上传题目自家做
- %~dp0表示什么意思
- 51nod 1092 回文字符串
- 高并发下Spring使用@Transactional 的问题
- G笔记_Java基础(变量、基本类型、运算符和表达式-1)[案例]
- 图像复原之维纳滤波
- 基于Linux下详解正则表达式(基本正则和扩展正则命令使用实例)
- 3. 指令 -- Highway MVVM
- 进程标识符
- 4. 宏指令 -- Highway MVVM
- 循坏赛日程表(分治)