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的子序列 ...
随机推荐
- iOS 数据持久化(2):SQLite3
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- xcode 6.4模拟器出现多个相同版本:OSX Yosemite 上安装xcode7 beta和xcode6.4
错误现象是:我在OSX Yosemite上同时安装了Xcode 7Beta和Xcode 6.4,然后Xcode 6.4的模拟器出现了重复版本.截图如下: 解决方法是: 删除该路径下的所有文件:~/Li ...
- oracle实现自动记录存储过程、自定义函数执行错误
CREATE OR REPLACE Package Pkg_Stm_Prgerrlog As --Purpose: 实现记录系统错误异常信息,便于问题跟踪 Procedure Sp_Stm_Prger ...
- U3D Trigger事件触发
使用Trigger事件触发,可以达到虽然触发了,可是不改变任何效果. 这个是进入时候触发的: void OnTriggerEnter2D(Collider2D other) { print (othe ...
- js中浮点型运算 注意点
先看张图: 这是一个JS浮点数运算Bug,导致我树状图,数据合计不正确,,,,,,两个小数相加,出来那么多位小数 (这是修该之后的) 网上找到以下解决方式: 方法一:有js自定义函数 <sc ...
- .Net 4.0 Convert Object to XDocument
将Object转换为XDocment对象 代码如下: C# – Object to XDocument using System; using System.Collections.Generic; ...
- 115个Java面试题和答案——终极列表
from http://www.importnew.com/10980.html#collection http://www.importnew.com/11028.html 下面的章节分为上下两篇, ...
- 【CF39E】【博弈论】What Has Dirichlet Got to Do with That?
Description You all know the Dirichlet principle, the point of which is that if n boxes have no less ...
- applicationContext.xml详解(转)
转自:http://blog.csdn.net/heng_ji/article/details/7022171,写的很好,省得以后找,放此处 想必用过Spring的程序员们都有这样的感觉,Spring ...
- yzoi1109&&viojs1042最小步数的一点看法——回文数
Description - 问题描述 有一天,雄霸传授本人风神腿法第一式:捕风捉影..............的步法(弟子一:堂主,你大喘气呀.风:你给我闭嘴.)捕风捉影的关键是换气(换不好就会大喘气 ...