uva 10026 Problem C: Edit Step Ladders
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的更多相关文章
- UVA - 10029 Edit Step Ladders (二分+hash)
Description Problem C: Edit Step Ladders An edit step is a transformation from one word x to another ...
- Edit Step Ladders - UVA 10029
题意 题目链接(Virtual Judge):Edit Step Ladders - UVA 10029 题意: 如果单词 \(x\) 能通过添加.删除或修改一个字母变换为单词 \(y\),则称单词 ...
- UVa 10029 - Edit Step Ladders
題目:已知一些字典序排列的單詞,問能從中找到最大的一個有序單詞集合, 使得集合中的單詞每一個是有上一個單詞經過一次變換得來的(增.刪.改). 分析:dp,LIS.最大遞增子序列,不過數據較大须要優化. ...
- UVA 10029 Edit Step Ladders ——(DAG求最长路)
题意:升序的给出一本若干个单词,每个单词都可删除一个字母,添加一个字母或者改变一个字母,如果任意一个操作以后能变成另外一个字典中的单词,那么就连一条有向边,求最长的长度. 分析:DAG的最长路和最短路 ...
- POJ2564:Edit Step Ladders
浅谈\(Trie\):https://www.cnblogs.com/AKMer/p/10444829.html 题目传送门:http://poj.org/problem?id=2564 记\(f[i ...
- UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序
题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱. 给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序. 只要按罚款/天数去从大到小排 ...
- 重新postgresql出现错误:Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed.
以前正常使用的postgresql,今天出现问题:报*.dll错误.百度了一下,只能重新安装 . 在重新安装过程中报:Problem running post-install step. Instal ...
- uva 10026 Shoemaker's Problem
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 10026 Shoemaker's Problem(排序)
题目连接:10026 Shoemaker's Problem 题目大意:有一个鞋匠接了n双要修的鞋子, 修每双鞋需要d天,每推迟一天修将亏损val元,问按什么样的顺序修鞋可以保证损失最少,如果有多种情 ...
随机推荐
- wxPython跨线程调用
版权所有,转载请注明出处:http://guangboo.org/2013/08/23/wxpython-non-gui-thread-call-gui-method 之前有介绍了<wxPyth ...
- 总结XX网app中webapp常见的前端错误。
在2016年12月至2017年1月,这一个月的时间内,我参与了易政网app中webapp前端项目的工作,下面将我在此次项目中犯的错误总结起来,以防下次再犯.也终于知道之前看的文章中的一段话所代表的意义 ...
- C++读写文件并排序
比如一条记录是 1987 9 2 1988 8 26 代表公司员工生日 然后需要读入到系统 现在需要放入容器,并且排序 最后输出到新的文件中,按照年龄由大到小. #include "stda ...
- [AngularJS] New in Angular 1.5 ng-animate-swap
<!DOCTYPE html> <html ng-app="MyApplication"> <head> <link rel=" ...
- 读取Excel数据绑定到Gridview进行显示
读取Excel数据绑定到Gridview进行显示示例代码. 读取excel代码 /// <summary> /// 读取Excel /// authon:codeo.cn /// < ...
- NYOJ-569最大公约数之和
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=569 此题目可以用筛选法的思想来做,但是用到一个欧拉函数 gcd(1,12)=1,gcd( ...
- SpringMVC06以对象的方式获取前台的数据
========创建需要的两个实体类================ public class School { private String sName; private String addres ...
- SQL 2008 清除数据库日志
USE [master]GOALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE DNName SET RECO ...
- canvas toDataUrl 跨域问题
使用canvas 的 toDataUrl方法会遇到跨域问题 chrome 会报下面的错误: Uncaught SecurityError: Failed to execute 'toDataURL' ...
- svg转换工具
package com.rubekid.springmvc.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOu ...