题意:给定一个字典,找出连续变换的最长路径。
思路:我只想说LIS不超时啊,只需要预处理求出每个字符串长度就ok了。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char e[25010][17];
int dp[25010]={0},l[25010];
bool ji(int pi,int pj,int li,int lj)
{
bool yes=true;
for(int i=0,j=0;i<li;i++,j++){
if(e[pi][i]==e[pj][j]) continue;
else if(!yes) return false;
else {yes=!yes;j--;}
}
return true;
}
bool jc(int pi,int pj,int li,int lj)
{
bool yes=true;
for(int i=0;i<li;i++){
if(e[pi][i]==e[pj][i]) continue;
else if(!yes) return false;
else yes=!yes;
}
return true;
}
bool jd(int pi,int pj,int li,int lj)
{
bool yes=true;
for(int i=0,j=0;j<lj;i++,j++){
if(e[pi][i]==e[pj][j]) continue;
else if(!yes) return false;
else {yes=!yes;i--;}
}
return true;
}
int main()
{
//freopen("in.txt","r",stdin);
int size=0;
while(cin.getline(e[size],17)) size++;
for(int i=0;i<size;i++) l[i]=strlen(e[i]);
int ans=0;
for(int i=0;i<size;i++){
int t=0;
for(int j=0;j<i;j++){
if(l[i]==l[j]+1&&ji(i,j,l[i],l[j])) t=max(t,dp[j]);
else if(l[i]==l[j]&&jc(i,j,l[i],l[j])) t=max(t,dp[j]);
else if(l[i]==l[j]-1&&jd(i,j,l[i],l[j])) t=max(t,dp[j]);
}
dp[i]=t+1;
ans=max(ans,t+1);
}
cout<<ans<<endl;
return 0;
}