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元,问按什么样的顺序修鞋可以保证损失最少,如果有多种情 ...
随机推荐
- Java集合中那些类是线程安全的
线程安全类 在集合框架中,有些类是线程安全的,这些都是jdk1.1中的出现的.在jdk1.2之后,就出现许许多多非线程安全的类. 下面是这些线程安全的同步的类: vector:就比arraylist多 ...
- 在windows下MySQLdb/MySQL-python的安装
学习Python的时候总是遇到各种各样的问题,很多问题我也百度了很久,谷歌了很多,发现很多人也遇到这种问题:但是答案又各种不同,因人而异吧! 问题:windows系统下 安装了mysql数据库 ...
- Android 4.2 通知通过PendingIntent启动Activity失败的问题
今天突然发现在Android 4.2手机上点击通知消息无法打开Activity的问题,具体Logcat信息如下: 01-09 11:37:43.733: WARN/ActivityManager(92 ...
- UITableView显示不全
先上图(不全图片): 正确图片: 原因例如以下: 1.在tableView的父视图的freme问题. 2.tableView本身的frame问题.大小依据自己的实际情况改过来就OK了 希望能够帮助到你 ...
- Android 从清单配置文件元数据中获取值
最近在上班工作当中,也尝到了一些新的知识,现总结如下(1)从AndroidManifest.xml配置文件中获取meta数据 // 从Manifest.xml配置文件中获取数据 public stat ...
- Vim的多窗口模式管理
Vim中的多窗口打开 vim中,默认的多窗口打开,是横向分割窗口. 进入vim编辑器以后,可以通过new命令,新建一个子窗口 :new “新建一个未命名窗口 :new name "新建一个 ...
- asp.net设置元素css的属性
controls.style.Add("css名称","css值") 添加class规则 control.cssclass="str_cssname& ...
- DNN - Modules - QR Code Generator
Dotnetnuke 平台上的二维码模块.支持DNN 7.x平台的安装 QR码(快速响应码)是二维条形码.随着移动设备市场正以快速的步伐,QR码正在成为非常重要的营销工具.与移动电话或平板电脑的扫描, ...
- 【转】#include,#import,@class的区别
#include #include <> :用于对系统文件的引用,编译器会在系统文件目录下去查找该文件. #include "xx.h ...
- 武汉科技大学ACM :1006: A+B for Input-Output Practice (VI)
Problem Description Your task is to calculate the sum of some integers. Input Input contains multipl ...