http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=970

通过对每一个字符串,每一个位置进行枚举三个操作,然后二分查找操作后的字符串是否存在,dp记录。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define N 25000
using namespace std; char g[N][];
char s[];
int dp[N*]; void change(char *g,char *s,int pos,char ch)
{
int k=strlen(g);
for(int i=; i<k; i++)
{
s[i]=g[i];
}
s[pos]=ch;
s[k]='\0';
} void add(char *g,char *s,int pos,char ch)
{
int k=strlen(g);
for(int i=; i<pos; i++)
{
s[i]=g[i];
}
s[pos]=ch;
for(int j=pos; j<k; j++)
{
s[j+]=g[j];
}
s[k+]='\0';
} void del(char *g,char *s,int pos)
{
int k=strlen(g);
for(int i=; i<pos; i++)
{
s[i]=g[i];
}
for(int j=pos+; j<k; j++)
{
s[j-]=g[j];
}
s[k-]='\0';
} void Get_change(char *g,char *s,char ch,int pos,int f)
{
if(f==) change(g,s,pos,ch);
else if(f==) add(g,s,pos,ch);
else if(f==) del(g,s,pos);
} int bs(char *s,int r)
{
r--;
int l=;
int mid;
while(l<=r)
{
mid=(l+r)>>;
if(strcmp(g[mid],s)==)
{
return mid;
}
else if(strcmp(g[mid],s)<)
{
l=mid+;
}
else
r=mid-;
}
return -;
}
int main()
{
//freopen("1.txt","r",stdin);
//freopen("2.txt","w",stdout);
int cnt=;
while(gets(g[cnt]))
{
cnt++;
}
int ans=;
for(int i=; i<cnt; i++)
{
dp[i]=;
for(int k=; k<=; k++)
{
for(int j=; j<(int)strlen(g[i]); j++)
{
for(int c=; c<; c++)
{
Get_change(g[i],s,'a'+c,j,k);
if(strcmp(g[i],s)<) break;
int x=bs(s,i);
if(x>=) dp[i]=max(dp[i],dp[x]+);
}
} }
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
return ;
}

uva 10026 Problem C: Edit Step Ladders的更多相关文章

  1. UVA - 10029 Edit Step Ladders (二分+hash)

    Description Problem C: Edit Step Ladders An edit step is a transformation from one word x to another ...

  2. Edit Step Ladders - UVA 10029

    题意 题目链接(Virtual Judge):Edit Step Ladders - UVA 10029 题意: 如果单词 \(x\) 能通过添加.删除或修改一个字母变换为单词 \(y\),则称单词 ...

  3. UVa 10029 - Edit Step Ladders

    題目:已知一些字典序排列的單詞,問能從中找到最大的一個有序單詞集合, 使得集合中的單詞每一個是有上一個單詞經過一次變換得來的(增.刪.改). 分析:dp,LIS.最大遞增子序列,不過數據較大须要優化. ...

  4. UVA 10029 Edit Step Ladders ——(DAG求最长路)

    题意:升序的给出一本若干个单词,每个单词都可删除一个字母,添加一个字母或者改变一个字母,如果任意一个操作以后能变成另外一个字典中的单词,那么就连一条有向边,求最长的长度. 分析:DAG的最长路和最短路 ...

  5. POJ2564:Edit Step Ladders

    浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:http://poj.org/problem?id=2564 记\(f[i ...

  6. UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序

    题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱. 给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序. 只要按罚款/天数去从大到小排 ...

  7. 重新postgresql出现错误:Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed.

    以前正常使用的postgresql,今天出现问题:报*.dll错误.百度了一下,只能重新安装 . 在重新安装过程中报:Problem running post-install step. Instal ...

  8. uva 10026 Shoemaker's Problem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. uva 10026 Shoemaker's Problem(排序)

    题目连接:10026 Shoemaker's Problem 题目大意:有一个鞋匠接了n双要修的鞋子, 修每双鞋需要d天,每推迟一天修将亏损val元,问按什么样的顺序修鞋可以保证损失最少,如果有多种情 ...

随机推荐

  1. 12、ERP设计之 系统基础管理(BS)- 模块与菜单的关联

    ShareERP2013-10-03 模块:具有功能设计.权限绑定,链接用户菜单与系统的重要桥梁. 菜单:是用于显示与用户交互的重要入口,更是导航系统的舵手,所以它的设计直接影响到用户体验. 菜单可能 ...

  2. WORLD OPERATS

        word文章设置无法复制 通常我们会采用设置密码的方式,规定某个文档的使用范围. 但这种方法是有一个局限,那就是可以观看文档的人未必靠谱,万一复制了文档的重要内容怎么办? 因此,不妨考虑加上禁 ...

  3. SKEmitterNode类

    继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架  /System/L ...

  4. msxml 操作xml

    1.简介 在.NET平台,微软为C#或托管C++程序员提供了丰富的类库,用以支持各种需求,其中就有对XML文件操作的丰富的类.例如XMLDocument, XmlElement等.但是C++标准库中并 ...

  5. VSS Get Latest Version 没有提示recursive的对话框解决

    今天按照VSS使用时,当“Get Latest version”时,不小心勾选了 “Only show this dialog when the Shift key is down”,因此当我再“Ge ...

  6. JSP九个隐式对象及作用域

    out:JspWriter实例对象,作用域为page(页面执行期) 向客户端输出内容 request:HttpServletRequest实例对象,作用域为request(用户请求期) 请求信息 re ...

  7. Linux 字符集

    摘抄自网络--/etc/sysconfig/i18n 文件:LANG="zh_CN.GB18030"SUPPORTED="zh_CN.GB18030:zh_CN:zh:e ...

  8. eclipse中svn版本不兼容问题

    eclipse中导入本地svn管理的Android项目 使用svn时弹出以下提示: org.apache.subversion.javahl.ClientException: Unsupported ...

  9. 以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。

    以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”. 报错内容如下: 解决办法如下: 1.在_Layout.cshtml布局body内 ...

  10. 数据类型转换中的一些特殊情况(JY06-JavaScript)

    1.字符串的不可变性 字符串定义了后,会一直占据内存空间,企鹅该处内存空间(栈)不可被重新赋值. 2.短路运算 ||.&& 二元运算符,返回参与运算的操作数的原值(原数据类型和原数据) ...