poj1159
来源:互联网 发布:中国出口武器 知乎 编辑:程序博客网 时间:2024/05/30 20:08
short int
#include <iostream>#include <cstdio>#include <cstring>#include <climits>#include <algorithm>using namespace std;char a[5001],b[5001];short int dp[5001][5001];int n;int solve(){ memset(dp,0,sizeof(dp)); for(int i=n-1,j=0;i>=0;--i,++j) b[j] = a[i]; for(int i=0;i<n;++i) for(int j=0;j<n;++j) if(*(a+i)==*(b+j)) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]); return n-dp[n][n];}int main(){ while(scanf("%d",&n)!=EOF) { scanf("%s",a); printf("%d\n",solve()); } return 0;}
roll
#include <iostream>#include <cstdio>#include <cstring>#include <climits>#include <algorithm>using namespace std;char a[5001],b[5001];short int dp[2][5001];int n;int r1=0,r2=1,temp;void cc(){ memset(dp[r1],0,sizeof(dp[r1])); temp=r1; r1=r2; r2=temp;}int solve(){ memset(dp,0,sizeof(dp)); for(int i=n-1,j=0;i>=0;--i,++j) b[j] = a[i]; for(int i=0;i<n;++i) { for(int j=0;j<n;++j) if(*(a+i)==*(b+j)) dp[r2][j+1]=dp[r1][j]+1; else dp[r2][j+1]=max(dp[r2][j],dp[r1][j+1]); cc(); } return n-dp[r1][n];}int main(){ while(scanf("%d",&n)!=EOF) { scanf("%s",a); printf("%d\n",solve()); } return 0;}
0 0
- poj1159
- poj1159
- poj1159
- poj1159
- poj1159
- POJ1159
- poj1159
- poj1159
- poj1159
- POJ1159
- poj1159
- POJ1159 Palindrome
- poj1159 DP
- poj1159 - Palindrome
- POJ1159 Palindrome
- POJ1159--Palindrome
- POJ1159 Palindrome
- poj1159 LCS
- 使用java模拟http请求时关于特殊字符的处理+
- svm常用核函数
- 彻底解决Android 拍照 内存溢出 Out of Memory的问题
- Oracle大数据常见优化查询
- Universal-Image-Loader源码阅读(29)-BitmapDisplayer
- poj1159
- Spring Cloud构建微服务
- Java编程的动态性(author Dennis M. Sosnoski )学习——学习笔记(1)
- 一个简单的volley网络请求
- 如何在linux下查看目录的剩余空间大小
- 删除链表中的重复元素
- java基于spring框架上传文件
- 写时拷贝
- 都在做百度SEO,你是否真的了解百度?