题意:看那张图就一清二楚了吧, N个序列首位相连(相同的序列部分),得到最短的总序列。
?
思路就是:将N个序列首尾相连能重合的长度求粗来。然后DFS枚举每种首尾相连的情况。
?
?
#include
#include
#include
#define N 22 #define INF 0x7fffffff using namespace std; int n,ans; int f[N][N],vis[N],len[N]; char str[N][N]; void get(int x,int y) //f[x][y],将y贴到x后面能减少的最大重复长度 { int i,j,l; for(l=len[y];l>0;l--) //枚举长度 { int ok=1; for(i=len[x]-l,j=0;i
ans) //剪枝~ return ; for(int i=0;i
?