Description
For a given dictionary, you are to compute the length of the longest edit step ladder.
cat dig dog fig fin fine fog log wine
5 题意:给你一个递增的字符串数组,给你三种操作方法变成其他的串,问你最长的可能 思路:hash+二分,dp[i]表示从i开始的串的最长变化可能,记忆化搜索#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 25010; const int HASH = 1000010; int n, head[HASH], next[MAXN], f[MAXN]; char b[MAXN][20], temp[20]; int hash(char *s) { int v = 0,seed = 131; while (*s) v = v * seed + *(s++); return (v & 0x7fffffff) % HASH; } void insert(int s) { int h = hash(b[s]); next[s] = head[h]; head[h] = s; } int search(char *s) { int i,h = hash(s); for (i = head[h]; i != -1; i = next[i]) if (!strcmp(b[i],s)) break; return i; } void add(char *s, int p, int d) { int i = 0, j = 0; while (i < p) temp[j++] = s[i++]; temp[j++] = 'a' + d; while (s[i]) temp[j++] = s[i++]; temp[j] = '