题解

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ; int n;
char s1[maxn], s2[maxn]; int d[maxn][maxn], a[maxn]; int main()
{
while(scanf("%s%s", s1 + , s2 + ) == )
{
n = strlen(s1 + );
for(int i = ; i <= n; i++) d[i][i] = ; for(int l = ; l <= n; l++)
for(int i = ; i + l - <= n; i++)
{
int j = i + l - ;
d[i][j] = d[i + ][j] + ;
for(int k = i + ; k <= j; k++) if(s2[i] == s2[k])
d[i][j] = min(d[i][j], d[i+][k-] + d[k][j]);
} if(s1[] == s2[]) a[] = ; else a[] = ;
for(int i = ; i <= n; i++)
{
a[i] = d[][i];
if(s1[i] == s2[i]) a[i] = a[i - ];
else
{
for(int j = ; j < i; j++) a[i] = min(a[i], a[j] + d[j+][i]);
}
} printf("%d\n", a[n]);
} return ;
}

代码君

HDU 2476 区间DP String painter的更多相关文章

  1. String painter HDU - 2476 -区间DP

    HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...

  2. [一道区间dp][String painter]

    http://acm.hdu.edu.cn/showproblem.php?pid=2476 String painter Time Limit: 5000/2000 MS (Java/Others) ...

  3. hdu 2476 区间dp

    题意: 给出两个串s1和s2,一次只能将一个区间刷一次,问最少几次能让s1=s2 例如zzzzzfzzzzz,长度为11,我们就将下标看做0~10 先将0~10刷一次,变成aaaaaaaaaaa 1~ ...

  4. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

  5. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  7. HDU 4632 区间DP 取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...

  8. hdu 4632(区间dp)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  9. HDU 5273 区间DP

    输入一组数,m次询问 问每一个询问区间的逆序数有多少 区间DP简单题 #include "stdio.h" #include "string.h" int dp ...

随机推荐

  1. ViewPager的使用总结

    这两天公司项目一直需要用到ViewPager来显示各式各样的Banner图,因而再次做了一些总结,不全后续应该还会更新的. 1.ViewPager要想做到一个界面显示多个items 有两种方式 ,一种 ...

  2. Solr查询中涉及到的Cache使用及相关的实现【转】

    转自:http://www.cnblogs.com/phinecos/archive/2012/05/24/2517018.html 本文将介绍Solr查询中涉及到的Cache使用及相关的实现.Sol ...

  3. H5存储

    1.localstorage ① 500万字符限制② 一般存储ajax请求返回数据,并且需要设置过期时间③ 具有清理机制,将过期数据清理④ 不存储敏感信息⑤ 不存储SEO依赖数据,至少不能严重依赖⑥ ...

  4. C# (Cookie)基本操作

    在Common中新建一个CookieHelper,全局调用 using System; using System.Collections.Generic; using System.Linq; usi ...

  5. ubuntu下lnmp添加虚拟目录没有权限

    lnmp.org下载的lnmp集成环境,通过lnmp vhost tsp创建了虚拟主机目录,将此目录导入到phpstorm中时提示错误,应该时权限的问题,想通过chmod -R 777 tsp来改变t ...

  6. Grace Huang 2017/1/12

    原文 Huang doesn't think of acting as pretending to be someone else.Rather,she considers it an opportu ...

  7. 洛谷 P1744 采购特价商品

    题目背景 <爱与愁的故事第三弹·shopping>第一章. 题目描述 中山路店山店海,成了购物狂爱与愁大神的“不归之路”.中山路上有n(n<=100)家店,每家店的坐标均在-1000 ...

  8. spark 的RDD各种转换和动作

    今天先把spark的各种基本转换和动作总结下,以后有时间把各种用法放上去. 1 RDD基本转换操作    map.flagMap.distinct coalesce.repartition coale ...

  9. Xcode4删除文件后missing file警告

    1.运行终端,执行命令行进入missing file目录,然后运行 svn delete nameOfMissingFile 或 git rm nameOfMissingFile 2.删除隐藏的.sv ...

  10. 关于bootstrap栅格系统的五等分以及八等分代码

    众所周知,bootstrap的栅格系统是基于十二等分的,今天拿到设计的设计稿一看,发现一个图片list上只有8张图片,然后上网查资料,发现只能自己写css代码实现,故写博客记录代码. 以下是八等分的代 ...