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元,问按什么样的顺序修鞋可以保证损失最少,如果有多种情 ...
随机推荐
- 关于xcode7编译旧项目崩溃-[UIApplication _runWithMainScene:transitionContext:completion:]
崩溃原因 crash: Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], / ...
- 只有20行Javascript代码!手把手教你写一个页面模板引擎
http://www.toobug.net/article/how_to_design_front_end_template_engine.html http://barretlee.com/webs ...
- Object -C 数组 -- 笔记
// // main.m // Array // // Created by facial on 23/8/15. // Copyright (c) 2015 facial_huo. All ...
- 微软下一代云环境Web开发框架ASP.NET vNext预览
微软在2014年5月12日的TechEd大会上宣布将会公布下一代ASP.NET框架ASP.NET vNext的预览.此次公布的ASP.NET框架与曾经相比发生了根本性的变化,凸显了微软"云优 ...
- Android 出现警告Exported service does not require permission
在配置Android清单文件的时候,配置service,或者activity,或者receive的时候,出现Exported service does not require permission警告 ...
- 大数据笔记05:大数据之Hadoop的HDFS(数据管理策略)
HDFS中数据管理与容错 1.数据块的放置 每个数据块3个副本,就像上面的数据库A一样,这是因为数据在传输过程中任何一个节点都有可能出现故障(没有办法,廉价机器就是这样的) ...
- NYOJ-1070诡异的电梯【Ⅰ】
这道题是个dp,主要考虑两种情况,刚开始我把状态转移方程写成了dp[i] = min(dp[i-1] + a, dp[i + 1] +b); 后来想想当推到dp[i]的时候,那个dp[i + 1]还没 ...
- 【iOS开发】emoji表情的输入思路
1.自定义一个表情包类继承NSTextAttachment #import <UIKit/UIKit.h> /** 表情包的自定义类*/ @interface EmojiTextAttac ...
- toString结果
String[] str = new String[] { "a", "b", "c" }; System.out.println(str) ...
- smarty半小时快速上手教程(转)
来源于:http://www.chinaz.com/program/2010/0224/107006.shtml 一:smarty的程序设计部分: 在smarty的模板设计部分我简单的把smarty在 ...