H - String painter
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; char s1[maxn];
char s2[maxn];
int dp[maxn][maxn];
int len;
int ans[maxn]; int main(){
Faster;
while(~scanf("%s%s", s1, s2)){
len = strlen(s1);
memset(dp, , sizeof(dp));
for(int j = ;j < len; j++){ //j为尾
for(int i = j;i >= ;i--){ //i为头
dp[i][j] = dp[i+][j] + ; //每个都单独刷一次
for(int k = i+;k <= j;k++){
if(s2[i] == s2[k]){
dp[i][j] = min(dp[i][j], (dp[i+][k]+dp[k+][j]));
}
}
}
}
for(int i = ;i < len;i++){
ans[i] = dp[][i];
}
for(int i = ;i < len;i++){
if(s1[i] == s2[i]){
ans[i] = ans[i-]; //对应位置相等的话,就不用刷新
}
else{
for(int j = ;j < i;j++){
ans[i] = min(ans[i], ans[j] + dp[j+][i]); //寻找j来分割区间的最优解
}
}
}
printf("%d\n", ans[len-]);
}
return ;
}
H - String painter的更多相关文章
- HDOJ 题目2474 String painter(区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 2476 String painter(区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU2476 String painter(DP)
题目 String painter 给出两个字符串s1,s2.对于每次操作可以将 s1 串中的任意一个子段变成另一个字符.问最少需要多少步操作能将s1串变为s2串. 解析 太妙了这个题,mark一下. ...
- [一道区间dp][String painter]
http://acm.hdu.edu.cn/showproblem.php?pid=2476 String painter Time Limit: 5000/2000 MS (Java/Others) ...
- hdu2476 String painter(区间dp)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2476 Problem Description There are two strings ...
- uva live 4394 String painter 间隔dp
// uva live 4394 String painter // // 问题是,在培训指导dp运动主题,乍一看,我以为只是一点点复杂 // A A磕磕磕,两个半小时后,.发现超过例子.然而,鉴于他 ...
- HDU2476 String painter
题意 String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Go -- php 中的pack("H*", $string) 转换成go
pack("H*", $string) 转化成这样: //16进制字符串转[]byte func HexToByte(hex string) []byte { length := ...
- 刷题总结——String painter(hdu2476)
题目: Problem Description There are two strings A and B with equal length. Both strings are made up of ...
随机推荐
- 详细阐述ping命令中请求超时与无法访问的区别
1.Request timed out 这是大家经常碰到的提示信息,很多文章中说这是对方机器置了过滤ICMP数据包,从上面工作过程来看,这是不完全 正确的,至少有下几种情况. (1) 对方已关机,或者 ...
- hadoop运行测试命令遇到的问题
2017-02-16 09:46:14,926 INFO mapreduce.Job: Task Id : attempt_1487148856575_0001_m_000001_0, Status ...
- Linux GCC常用命令学习
1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...
- Can't locate Log/Dispatch.pm in @INC
记录一下配置mha的时候遇到的错误,使用perl模块发送邮件的时候报以下错误: # masterha_check_ssh --conf=/data/mha/app1.cnf Can't locate ...
- Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone.
Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecogn ...
- 利用Powershell在IIS上自动化部署网站
本文主要讲如何通过Powershell在IIS上自动化部署ASP.NET网站,而不涉及Powershell的基本语法,如果没有Powershell基础的同学也可以把本文作为学习Powershell的基 ...
- disablescroll
页面的设置 disablescroll:true(需要配合设置 enablePullDownRefresh:false ) 可以实现页面上下不能滑动 另一种实现方法: 设置页面的根元素 绝对定位, p ...
- 从使用os.system)在python命令(重定向标准输入输出
从使用os.system)在python命令(重定向标准输入输出 python 标准输出stdout stdio os.system通常我可以通过改变sys.stdout的值在python更改标准输出 ...
- 使用 NSData 分类实现,对 NSData 数据类型进行 AES 加密
一般对NSData的数据类型进行加密,这里就将 .h .m 文件分享出来,有需要的可以直接粘贴使用. 下面是 .h 文件 #import <Foundation/Foundation ...
- 如何在ubuntu下使用windows下的程序(eg: .exe)
为了在ubutu下安装百度云管家,上网查了下如何在ubuntu 下安装.exe文件,其中遇到一些问题记录如下: 使用的命令: 开始时直接使用的sudo apt-get install wine 在运行 ...