显然需要贪心,重叠越长越好,这样最终的串长尽可能短。
需要注意的是,不要考虑中间结果,显然是个状态dp。
先做预处理去重,然后求任意一对串的公共长度。
1 /* 3828 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector> 10 #include <deque> 11 #include <bitset> 12 #include <algorithm> 13 #include <cstdio> 14 #include <cmath> 15 #include <ctime> 16 #include <cstring> 17 #include <climits> 18 #include <cctype> 19 #include <cassert> 20 #include <functional> 21 #include <iterator> 22 #include <iomanip> 23 using namespace std; 24 //#pragma comment(linker,"/STACK:102400000,1024000") 25 26 #define sti set<int> 27 #define stpii set<pair<int, int> > 28 #define mpii map<int,int> 29 #define vi vector<int> 30 #define pii pair<int,int> 31 #define vpii vector<pair<int,int> > 32 #define rep(i, a, n) for (int i=a;i<n;++i) 33 #define per(i, a, n) for (int i=n-1;i>=a;--i) 34 #define clr clear 35 #define pb push_back 36 #define mp make_pair 37 #define fir first 38 #define sec second 39 #define all(x) (x).begin(),(x).end() 40 #define SZ(x) ((int)(x).size()) 41 #define lson l, mid, rt<<1 42 #define rson mid+1, r, rt<<1|1 43 44 45 const int INF = 0x3f3f3f3f; 46 const int maxl = 70; 47 const int maxn = 16; 48 const int mod = 1000000009; 49 __int64 a[maxn]; 50 char word[maxn][maxl]; 51 string sw[maxn]; 52 int nxt[maxl]; 53 int Len[maxn]; 54 bool visit[maxn]; 55 int dp[1<<16][16]; 56 int M[16][16]; 57 int n; 58 59 void f(char *s, __int64 x) { 60 int l = 0; 61 while (x) { 62 s[l] = (x & 1) + '0'; 63 ++l; 64 x >>= 1; 65 } 66 s[l] = '