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. POJ 3669 广度优先搜索

    题意:巨大流星雨即将袭来.每个流星会对击中的地方以及周围(上下左右四格)造成破坏.Bessie开始时位于(0, 0)位置,并希望逃到一处不会被袭击到的地方(在第一象限内).已知每移动一格需要1个时间单 ...

  2. I - Agri-Net - poj 1258

    貌似就是个裸的最小生成树啊 ******************************************************************************* #inclu ...

  3. top -Hp pid 显示所有的线程

    可以显示所有的线程 top -Hp pid [root@jiangyi01.sqa.zmf /home/ahao.mah] #top -Hp 41330 top - 22:49:40 up 27 da ...

  4. redis取值报错

    > get "all_couriers_on_the_job" (error) ERR Operation against a key holding the wrong k ...

  5. 【深入了解cocos2d-x 3.x】定时器(scheduler)的使用和原理探究(3)

    上篇文章分析到了定时器的定义.这篇的重点就是定时器是怎样执行起来的. 1.从main中寻找定时器的回调 讲定时器的执行,就不得不触及到cocos2dx的main函数了,由于定时器是主线程上执行的.并非 ...

  6. Linux 磁盘挂载和mount共享

      针对Linux服务器的磁盘挂载mount和共享做简单操作说明: 1.  查看已使用的磁盘情况 df –h 2.  查看所有磁盘 fdisk –l 3.  查看指定磁盘“/dev/xvde”的分区情 ...

  7. 转 [教程] Unity3D中角色的动画脚本的编写(二)

              在上一篇,我们介绍了有关Animation这个类中的部分方法,我后来想了想,这么介绍也不是个办法(其实有些方法我自己也没用过),该介绍点实际的东西了,毕竟我们是要做东西出来的.那好 ...

  8. 《UNIX网络编程》之多客户连接服务端,可重用套接字对

    该网络编程之客户端与服务端程序模板支持: 1. 多客户端同时连接服务端,即服务程序可以同时为多个客户端服务: 2. 服务端支持套接字对重用,即即使处于TIME_WAIT状态,仍可支持服务端重启: 3. ...

  9. 批量升级BMC固件asu64、ipmitool

    需求:通过服务器远程管理IP批量升级IMM.UEFI固件 工具:asu64.ipmitool.iflash64.cdc_interface.sh 下载:http://pan.baidu.com/s/1 ...

  10. Javascript 第一阶段 学习使用总结

    JavaScript 是一种轻量级的编程语言.JavaScript 是可插入 HTML 页面的编程代码.脚本可被放置在 HTML 页面的 <body> 和 <head> 部分中 ...