rt,TLE可以理解,可为什么会错啊。。。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}
inline int dec(int x,int v,int mod){x-=v;return x<0?x+mod:x;}
inline int read(){int x=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;}
inline void write(int x){if(x==0){putchar(48);return;}int len=0,dg[20];while(x>0){dg[++len]=x%10;x/=10;}for(register int i=len;i>=1;i--)putchar(dg[i]+48);}
const int N=1000005;
char ch[20][20];
int n,m,len[20],idx,head[N],to[N],nex[N],maxn,tim;
bool vis[N];
bool ask[N][6][6];
bool clac(int a,int b){//把b拼在a后面
if(ch[a][len[a]-1]==ch[b][0]) return true;
return false;
}
void add(int u,int v){
nex[++idx]=head[u];
to[idx]=v;
head[u]=idx;
return ;
}
void dfs(int now,int nowans){
maxn=max(maxn,nowans);
for(int i=head[now];i;i=nex[i]){
int y=to[i];
if(vis[y]) continue;
vis[y]=true;
dfs(y,nowans+len[y]);
vis[y]=false;
}
return ;
}
int main(){
tim=clock();
n=read();
for(int i=1;i<=n;i++){
scanf("%s",ch[i]);
len[i]=strlen(ch[i]);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(clac(i,j)){
add(i,j);
}
}
}
for(int i=1;i<=n;i++){
vis[i]=true;
dfs(i,len[i]);
vis[i]=false;
}
cout<<maxn;
system("Pause");
return 0;
}