HDU4681 String(dp)
题目链接。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string> using namespace std; const int maxn = +; char s1[maxn], s2[maxn], s3[maxn];
int dp1[maxn][maxn], dp2[maxn][maxn];
int que1[maxn][], que2[maxn][]; void max_dp(char *s1, char *s2, int (*dp)[maxn]) {
int len1 = strlen(s1), len2 = strlen(s2); for(int i=; i<len1; i++) dp[i][] = ;
for(int i=; i<len2; i++) dp[][i] = ; for(int i=; i<=len1; i++) {
for(int j=; j<=len2; j++) {
if(s1[i-] == s2[j-]) dp[i][j] = dp[i-][j-]+;
else dp[i][j] = max(dp[i-][j], dp[i][j-]);
}
}
} void str_rev(char *s) {
int len = strlen(s);
for(int i=; i<len/; i++) swap(s[i], s[len--i]);
} int get_str(char *s1, char *s2, int (*que)[]) {
int len1 = strlen(s1), len2 = strlen(s2);
int n = ; for(int i=; i<len1; i++) {
if(s1[i] == s2[]) {
int k = , j;
for(j=i+; j<len1; j++) {
if(s1[j] == s2[k]) k++;
if(k == len2) break;
}
if(k == len2) {
que[n][] = i;
que[n++][] = j;
}
}
} return n;
} int main() {
int T; scanf("%d", &T);
for(int kase=; kase<=T; kase++) {
scanf("%s %s %s", s1, s2, s3); int len1 = strlen(s1);
int len2 = strlen(s2);
int len3 = strlen(s3); int n1 = get_str(s1, s3, que1);
int n2 = get_str(s2, s3, que2); max_dp(s1, s2, dp1); str_rev(s1);
str_rev(s2); max_dp(s1, s2, dp2); int ans = ;
for(int i=; i<n1; i++) {
for(int j=; j<n2; j++) {
ans = max(ans, dp1[que1[i][]][que2[j][]]+dp2[len1-que1[i][]-][len2-que2[j][]-]+len3);
}
} printf("Case #%d: ", kase);
printf("%d\n", ans);
} return ;
}
HDU4681 String(dp)的更多相关文章
- hdu 4055 Number String(dp)
Problem Description The signature of a permutation is a string that is computed as follows: for each ...
- hdu5707-Combine String(DP)
Problem Description Given three strings a, b and c , your mission is to check whether c is the combi ...
- CodeForces - 710E Generate a String (dp)
题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...
- HDU4055 - number string(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 思路:dp[i][j]表示处理前i个字符以j结尾可能的序列数. 当a[i]=='I'时,dp[i ...
- HDU 4055:Number String(DP计数)
http://acm.hdu.edu.cn/showproblem.php?pid=4055 题意:给一个仅包含‘I','D','?'的字符串,’I'表示前面的数字比后面的数字要小(Increase升 ...
- Educational Codeforces Round 16 E. Generate a String (DP)
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...
- HDU 5707 Combine String (DP,LCS变形)
题意:给定三个字符串,问你第三个是不是由第一个和第二个组成的. 析:当时比赛是没有做出来啊...一直WA,就是没有判断长度,第一个和第二个和是不是和第三个一样,这个忘记... 我们用d[i][j]表示 ...
- HDU-4681 String 枚举+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 题意:给A,B,C三个串,求一个最长的串D,满足D是A和B的subsequence,C是D的su ...
- HUST 4681 String (DP LCS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 题目大意:给定三个字符串A,B,C 求最长的串D,要求(1)D是A的字序列 (2)D是B的子序列 ...
随机推荐
- 当升级新版本的时候,从新加载新版本的js的方法
<script src="../Script/SmcScript.js?version='<%=Smc20.Web.WebForm.Public.WebConst.WEBJSCA ...
- ASP.NET 动态属性筛选和分页绑定
分页控件为:AspNetPager.dll 我们先建立一个产品属性名称表 CREATE TABLE ProductAttr ( ,) NOT NULL primary key, [ParentID] ...
- 知识点摸清 - - position属性值之relative与absolute
两者共同特点是: 改变文档流 激活元素left.top.right.bottom.z-index属性 让元素”浮起来“,z-index>0 不同的是: 1.position:relative 会 ...
- document.documentElement.style判断浏览器是否支持Css3属性
1.document.documentElement.style 属性定义了当前浏览器支持的所有Css属性 包括带前缀的和不带前缀的 例如:animation,webkitAnimation,msAn ...
- CSS Clip剪切元素实例
一.实例1: .fixed { position: fixed; width: 382px; height: 100px; background: red; border: 1px solid blu ...
- Nginx配置http强制跳转到https
目的:访问http://sdk.open.test.com/时强制自动跳转到https://sdk.open.test.com/ 修改nginx站点配置文件sdk.open.test.com.conf ...
- [转载]hadoop SecondNamenode详解
SecondNamenode名字看起来很象是对第二个Namenode,要么与Namenode一样同时对外提供服务,要么相当于Namenode的HA.真正的了解了SecondNamenode以后,才发现 ...
- hdoj 1060
代码: #include <stdio.h>#include <math.h> int main(){ int t; while(scanf("%d&qu ...
- Ubuntu1404+Django1.9+Apache2.4部署配置1安装
关于Ubuntu环境下的文章很少,搜索一些问题比较麻烦,这里将别人的做法和自己做的整合一下.这篇文章主要讲解基础的安装,至于Django1.9如何部署到Apache2.4请转到下一篇博文http:// ...
- 第17章课后题(高级Perl技巧)
17.1 写一个程序,从文件中读取一组字符串(每行一个),然后让用户键入模式以便进行字符串匹配. 对于每个模式,程序应该说明文件里共有多少字符串匹配成功,分别是哪些字符串. 对于所键入的每个新模式,不 ...