nyoj_37 回文字符串
来源:互联网 发布:cecs钢结构绘图软件 编辑:程序博客网 时间:2024/06/06 04:52
原题链接》》》
解法描述:
输入字符串为s,将s逆置存到s1,然后求出s与s1的最长公共子序列(dp),最后用s长度len-dp,所得即为所求!!!
求最长公共子序列的算法》》》
#include<stdio.h>#include<string.h>char s[1005];int dp[1005][1005];void str_ver(char str[],char str1[]){ int len=strlen(str); int j=0; for(int i=len-1;i>=0;i--){ str1[j++]=str[i]; } str1[j]='\0';}int Max(int a,int b){ return a>b?a:b;}int main(){ int N; scanf("%d",&N); while(N--){ scanf("%s",s); int len=strlen(s); memset(dp,0,sizeof(dp)); char s1[1005]; str_ver(s,s1); //规划求最长子序列! for(int i=0;i<len;i++){ for(int j=0;j<len;j++){ if(s[i]==s1[j]){ dp[i+1][j+1]=dp[i][j]+1; }else{ dp[i+1][j+1]=Max(dp[i][j+1],dp[i+1][j]); } } } printf("%d\n",len-dp[len][len]); } return 0;}
0 0
- 回文字符串(nyoj_37)
- nyoj_37 回文字符串
- nyoj_37 回文字符串
- 还是回文 && 回文字符串
- 字符串回文
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- 字符串回文
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- 回文字符串
- RabbitMQ与AMQP协议详解
- 关于AndroidStudio中(有关详细信息, 请使用 -Xlint:deprecation 重新编译)的错误解决方案!
- Swift3.0-基础知识点
- 1025. PAT Ranking (25)
- 利用终端进行自动打包--Xcodebuild
- nyoj_37 回文字符串
- ISO 15765
- IDEA 中给 main 方法赋 args 参数
- 数字断点间隔
- 关于查询和"1"号的同学学习的课程完全相同的其他同学的信息详细
- 折半查找
- Django - 一个简单的界面显示实现
- Window 10上安装 linux centOS 7 --> 双系统
- 简单背包问题2 NOIP 2001 <dp/枚举>_水_