String painter (区间dp)
InputInput contains multiple cases. Each case consists of two lines:
The first line contains string A.
The second line contains string B.
The length of both strings will not be greater than 100.
OutputA single line contains one integer representing the answer.Sample Input
zzzzzfzzzzz
abcdefedcba
abababababab
cdcdcdcdcdcd
Sample Output
6
7 区间dp,但是具体实现,没实现,参考了一下题解:链接:https://blog.csdn.net/martinue/article/details/45953229
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std; int a[],dp[][];
char s1[],s2[];
int solve(int i,int j)
{
if(dp[i][j]!=-)
return dp[i][j];
if(i>j)
return dp[i][j]=;
if(i==j)
return dp[i][j]=;
dp[i][j]=solve(i+,j)+;
for(int k=i+;k<=j;k++)
if(s2[k]==s2[i])
dp[i][j]=min(solve(i+,k)+solve(k+,j),dp[i][j]);
return dp[i][j];
} int main ()
{
while(cin>>s1>>s2)
{
memset(dp,-,sizeof(dp));memset(a,,sizeof(a)); int len =strlen(s1);
for(int i=;i<len;i++)
{
for(int j=i;j<len;j++)
int t=solve(i,j);
}
for(int i=;i<len;i++)
{
a[i]=dp[][i];
if(s1[i]==s2[i])
{
if(i==)
a[i]=;
else
a[i]=a[i-];
}
else
{
for(int j=;j<i;j++)
a[i]=min(a[i],a[j]+dp[j+][i]);
}
}
printf("%d\n",a[len-]);
}
return ;
}
String painter (区间dp)的更多相关文章
- hdu2476 String painter(区间dp)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2476 Problem Description There are two strings ...
- HDU2476 String painter —— 区间DP
题目链接:https://vjudge.net/problem/HDU-2476 String painter Time Limit: 5000/2000 MS (Java/Others) Me ...
- uva live 4394 String painter 区间dp
// uva live 4394 String painter // // 这一题是训练指南上dp专题的习题,初看之下认为仅仅是稍微复杂了一点 // 就敲阿敲阿敲,两个半小时后,发现例子过了.然而自己 ...
- HDU2476 String painter——区间DP
题意:要把a串变成b串,每操作一次,可以使a串的[l,r]区间变为相同的一个字符.问把a变成b最少操作几次. 这题写法明显是区间dp ,关键是处理的方法. dp[l][r]表示b串的l~r区段至少需要 ...
- HDU 2476 String painter(区间dp)
题意: 给定两个字符串,让求最少的变化次数从第一个串变到第二个串 思路: 区间dp, 直接考虑两个串的话太困难,就只考虑第二个串,求从空白串变到第二个串的最小次数,dp[i][j] 表示i->j ...
- HDU 2476 String painter(区间DP+思维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意:给你字符串A.B,每次操作可以将一段区间刷成任意字符,问最少需要几次操作可以使得字符串 ...
- hdu 2476"String painter"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给定字符串A,B,每次操作可以将字符串A中区间[ i , j ]的字符变为ch, ...
- uva live 4394 String painter 间隔dp
// uva live 4394 String painter // // 问题是,在培训指导dp运动主题,乍一看,我以为只是一点点复杂 // A A磕磕磕,两个半小时后,.发现超过例子.然而,鉴于他 ...
- hdu_2476_String painter(区间DP)
题目链接:hdu_2476_String painter 题意: 有a,b两字符串,现在你有一个刷子,每次可以任选一个区间,使这个区间变成你想要的字符,现在让你将a变成b,问最少刷多少次 题解: 考虑 ...
- [CF1107E]Vasya and Binary String【区间DP】
题目描述 Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of l ...
随机推荐
- Android ExpandListView的用法(补上昨天的)(今天自习)
今天自习写ExpandListView的作业,昨天没写博客就是去写作业去了. 今天来说昨天内容吧! 其实ExpandListView和ListView的用法大同小异. 首先就是创建一个自己的适配器(现 ...
- MyFirstJavaWeb
源代码: Register.jsp <%@ page language="java" contentType="text/html; charset=utf-8&q ...
- CentOS7 安装 SonarQube
安装 SonarQube 环境 系统 CentOS 7 数据库 postgresql 10 系统配置 查看系统配置 sysctl vm.max_map_count sysctl fs.file-max ...
- java SFTP工具类
需要导入jsch-0.1.52.jar import java.io.File; import java.io.FileInputStream; import java.io.FileOutputSt ...
- Python+Pytest+Allure+Git+Jenkins接口自动化框架
Python+Pytest+Allure+Git+Jenkins接口自动化框架 一.接口基础 接口测试是对系统和组件之间的接口进行测试,主要是效验数据的交换,传递和控制管理过程,以及相互逻辑依赖关系. ...
- windows10永久激活工具 新版win10激活工具(绝对有效的永久激活工具)
来看这篇文章的,都用过KMS了吧?对!KMS是批量激活的,激活时间是一年,如果给女神激活,此法首选呀!!!但是帮基友激活,过了一年又来找自己,作为程序员的你,脸上是不是有点挂不住然后又不想花钱去买某宝 ...
- 源码解析JDK1.8-HashMap链表成环的问题解决方案
前言 上篇文章详解介绍了HashMap在JDK1.7版本中链表成环的原因,今天介绍下JDK1.8针对HashMap线程安全问题的解决方案. jdk1.8 扩容源码解析 public class Has ...
- Javascript模块化编程(一):模块的写法 (转)
Javascript模块化编程(一):模块的写法 原文作者: 阮一峰 日期: 2012年10月26日 随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞 ...
- Jmeter 常用函数(6)- 详解 __P
如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 作用 和 __property 作用一样,不 ...
- Jmeter 常用函数(30)- 详解 __if
如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 作用 判断给定条件是否成立 语法格式 ${_ ...