HDU 3831 DICS
意甲冠军:
按标题给4操作模式 用最少的次数 离a串行转换b弦
思路:
因为操作仅仅有这4种 所以我们能够确定从头到位去匹配a和b一定是正确的
那么状态数一共同拥有多少呢 一共同拥有length[a]*length[b]*(1+num(a~z)+num(A~Z)) 状态不多 能够用dp解决
上述计算状态能够表示为dp[i][j][k] 即a串匹配到i同一时候b串匹配到j k表示改动后缀操作改动成的字符
那么仅仅须要打表出全部的dp 同一时候利用dp+(lena-i)+(lenb-j)更新ans就可以
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef unsigned long long LL;
#define N 505
#define M 53
#define inf 100000000 int ans;
int dp[N][N][M];
char f[N], g[N]; int change(char u) {
if (u >= 'A' && u <= 'Z')
return u - 'A' + 1;
if (u >= 'a' && u <= 'z')
return u - 'a' + 27;
return 0;
} int main() {
int i, j, k, ans, lf, lg;
while (~scanf("%s", f)) {
if (!strcmp(f, "#"))
break;
scanf("%s", g);
lf = strlen(f);
lg = strlen(g);
for (i = 0; i <= lf; i++) {
for (j = 0; j <= lg; j++) {
for (k = 0; k < M; k++)
dp[i][j][k] = inf;
}
}
ans = inf;
dp[0][0][0] = 0;
for (i = 0; i <= lf; i++) {
for (j = 0; j <= lg; j++) {
for (k = 0; k < M; k++) {
if (dp[i][j][k] == inf)
continue;
ans = min(ans, dp[i][j][k] + lf - i + lg - j);
if (i == lf || j == lg)
continue;
if ((!k && f[i] == g[j]) || (k && k == change(g[j]))) {
//same
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k],
dp[i][j][k]);
} else {
//delete
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + 1);
//insert
dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i][j][k] + 1);
//change
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k],
dp[i][j][k] + 1);
//Suffix change
dp[i + 1][j + 1][change(g[j])] = min(
dp[i + 1][j + 1][change(g[j])],
dp[i][j][k] + 1);
}
}
}
}
printf("%d\n", ans);
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 3831 DICS的更多相关文章
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- HDU 3264/POJ 3831 Open-air shopping malls(计算几何+二分)(2009 Asia Ningbo Regional)
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- URAL1113(数学)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1113 根据样例分析: 1.沙漠只有500公里或者更短,这时很简单,一次搞定. 2.沙漠6 ...
- Eclipse中的Maven项目报Unbound classpath variable错误
今天更新了最新版的Eclipse luna 4.4版本号,svn更新了项目后,系统一直报错,经查看在Problems窗体中发现一堆错误.提演示样例如以下: Unbound classpath ...
- C#应用Newtonsoft.Json.dll,控制json的时间格式
原文:C#应用Newtonsoft.Json.dll,控制json的时间格式 var aIsoDateTimeConverter = new IsoDateTimeConverter();aIsoDa ...
- centos7图形配置 firewall-config
图形配置 firewall-config centos 7:systemctl stop firewalld.service #停止
- IIS设置允许下载.exe文件解决方法
最近很多客户使用IIS服务器,然后提示返现宝下载无法找到等无法下载的问题. 返现宝是.exe安装文件,部分服务器或主机可能无法下载. 第一.如果是自己服务器或VPS请按如下设置: 1.设置MIME,让 ...
- 局部敏感哈希-Locality Sensitive Hashing
局部敏感哈希 转载请注明http://blog.csdn.net/stdcoutzyx/article/details/44456679 在检索技术中,索引一直须要研究的核心技术.当下,索引技术主要分 ...
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在使用Hibernate的J2EE项目中,莫名其妙出现如上错误,既不报错,也不运行不论什么输出測试代码,更不返回结果. 经过排查,在方法里面引用的实体类和其映射文件属性个数不一致. 改动一致后,即解决 ...
- HUNNU11351:Pythagoras's Revenge
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11351&courseid=0 Problem des ...
- The OpenGL pipeline
1. Vertex Data 2. Vertex Shader 3. Tessellation Control Shader 4.Tessellation evaluation Shader 5. G ...
- java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
Myeclipse 8.6使用tomcat7时间.执行javaweb如报告了以下错误项: java.lang.NoClassDefFoundError: org/apache/juli/logging ...