DP,MLE后改为滚动数组AC。

 #include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 5001
#define INF 0x3f3f3f3f
char str[MAXN];
short dp[][MAXN]; int getmin(int x, int y) {
return x<y ? x:y;
} int main() {
int n;
int i, j, k; while (scanf("%d", &n) != EOF) {
scanf("%s", str+);
memset(dp, , sizeof(dp));
for (i=n; i>; --i) {
k = i&;
for (j=i+; j<=n; ++j) {
if (str[i] == str[j]) {
dp[k][j] = dp[!k][j-];
} else {
dp[k][j] = getmin(dp[!k][j], dp[k][j-]) + ;
}
}
}
printf("%d\n", dp[][n]);
} return ;
}

【HDOJ】1513 Palindrome的更多相关文章

  1. 【动态规划】POJ3280- Cheapest Palindrome

    [题目大意] 给出一个字符串,可以删除或添加一些字符,它们各自会消耗价值.问最少消耗多少价值,可以使得字符串变成回文的. [思路] 事实上删除或添加字符的价值只需要保持较小的那一个.假设当前要将(j, ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. 【leetcode】Valid Palindrome

    题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  4. 【leetcode】Shortest Palindrome(hard)★

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  5. 【题解】【字符串】【Leetcode】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  6. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  7. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  8. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  9. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

随机推荐

  1. SpringMVC 自定义拦截资料

    1.springmvc学习笔记(28)——自定义拦截器 2.Spring MVC HandlerInterceptor Annotation Example with WebMvcConfigurer ...

  2. @Query注解的用法(Spring Data JPA)

    参考文章:http://www.tuicool.com/articles/jQJBNv 1. 一个使用@Query注解的简单例子 @Query(value = "select name,au ...

  3. WASD控制UI界面血条加减

    using UnityEngine; using System.Collections; using UnityEngine.UI; public class HealthController : M ...

  4. python批量改动指定文件夹文件名称

    这小样例仅仅要是说明用python怎么批量改动指定文件夹的文件名称: 记得要把脚本跟改动的文件放在同一个文件夹下 #encoding:utf-8 import os import sys files ...

  5. android:ellipsize的使用

    EidtText和textview中内容过长的话自动换行,使用android:ellipsize与android:singleine可以解决,使只有一行. EditText不支持marquee 用法如 ...

  6. mac下的home键、end键以及insert键的替代

    最近用android模拟器模拟东西,发现模拟器的home快捷键是键盘上的home键,这让我在windows下很好找,换到mac下找了老半天也没找到,后来才查到是有替代键的,放到这里做备份 home键f ...

  7. SSH端口修改

    打开SSDH配置文件: vim /etc/ssh/sshd_config 添加端口号:Port 60000 重启服务:service sshd restart

  8. 矩阵快速幂(入门) 学习笔记hdu1005, hdu1575, hdu1757

    矩阵快速幂是基于普通的快速幂的一种扩展,如果不知道的快速幂的请参见http://www.cnblogs.com/Howe-Young/p/4097277.html.二进制这个东西太神奇了,好多优秀的算 ...

  9. 美洽SDK

    简介 GitHub地址:https://github.com/Meiqia/MeiqiaSDK-Android 开发文档:http://meiqia.com/docs/meiqia-android-s ...

  10. Remoting 的“传递的引用”理解

    WCf是集大成者,具有其他微软的很多技术,其中分布式上很多借助于Remoting,所以研究一下Remoting有助于理解WCF 提到Remoting就不得不涉及到MarshalByRefObject这 ...