hdu2476】的更多相关文章

题目链接:https://vjudge.net/problem/HDU-2476 String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5023    Accepted Submission(s): 2375 Problem Description There are two strings A and B wit…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2476 Problem Description There are two strings A and B with equal length. Both strings are made up of lower case letters. Now you have a powerful string painter. With the help of the painter, you c…
//Accepted 300 KB 31 ms //区间dp 思路完全网上看的 #include <cstdio> #include <cstring> #include <iostream> using namespace std; ; int dp[imax_n][imax_n]; char s1[imax_n],s2[imax_n]; int ans[imax_n]; int n; int min(int a,int b) { return a<b?a:b;…
题意:要把a串变成b串,每操作一次,可以使a串的[l,r]区间变为相同的一个字符.问把a变成b最少操作几次. 这题写法明显是区间dp ,关键是处理的方法. dp[l][r]表示b串的l~r区段至少需要刷几次.这个值直接在b串中讨论,不用考虑a串. 之后用一个数组ans[i]来帮助求答案,ans[i]表示把a串的[0,i]区段刷成b对应区段所刷的次数. #include<iostream> #include<string.h> using namespace std; ][]; #d…
/* dp[l][r]表示将任意串的[l,r]刷成s2样子的最小代价 ans[i]表示将s1的前i位刷成s2的代价 按照区间dp的常用做法,dp[l][r]的状态由dp[l][k],dp[k+1][r]决定 若s2[l]==s2[k],那么在刷k的时候也能刷到l,dp[l][r]=min(dp[l][r],dp[l+1][k]+dp[k+1][r]) 但是有可能所有的s[k]!=s[l],即s2[l]要被单独刷一次,那么dp[l][r]要被赋初值dp[l][r]=1+dp[l+1][r] 第二步…
题意 String painter Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6669    Accepted Submission(s): 3230 Problem Description There are two strings A and B with equal length. Both strings are made…
http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意是给定一个起始串和一个目标串,然后每次可以将某一段区间染成一种字符,问从起始串到目标串最少需要染多少步? 读完题首先会想到的自然是用区间dp,但是列出来发现,没办法区间合并.因为一旦需要考虑对某一段成段染色的话,在区间合并的时候,就无法考虑转移过程中起始串的变化了. 既然这样,就不考虑成段染色造成的影响了,就当起始串和目标串处处不想等. 那么考虑区间[i, i+len], 自然遍历子区间[i, …
题目: Problem Description There are two strings A and B with equal length. Both strings are made up of lower case letters. Now you have a powerful string painter. With the help of the painter, you can change a segment of characters of a string to any o…
好难搞得东西.... 题意都懒得写了,看题解的巨巨莫怪啊,未完待续未完待续,回去睡觉.…
题目 String painter 给出两个字符串s1,s2.对于每次操作可以将 s1 串中的任意一个子段变成另一个字符.问最少需要多少步操作能将s1串变为s2串. 解析 太妙了这个题,mark一下. 这个题先考虑怎么由空串转化s2, \(f[i][j]\)表示从空串到s2最少的次数, 则有\(f[i][j]=s[i+1][j]+1\), 若\([i+1,j]\)存在一个\(k\),使\(s2[i]==s2[k]\),则\(f[i][j]=min\{f[i+1][k]+f[k+1][j]\}\)…