标签:include 老年人 printf nbsp mes size pre i++ can
1.搜索
#include <cstdio> #include <string> #include <iostream> #include <algorithm> using namespace std; int n, ans; string s[21]; int vis[21]; void dfs(int a, int len) { ans = max(len, ans); printf("%d %d\n", ans, len); if (vis[a] == 2) return; vis[a]++; for (int i = 0; i < s[a].size(); i++) for (int j = 1; j <= n; j++) { if (i == 0 && a != 0) break; int l = i, r = 0; while(s[a][l] == s[j][r]) l++, r++; if (l == s[a].size()) dfs(j, len + s[j].size() - (s[a].size() - i)); } vis[a]--; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) cin >> s[i]; cin >> s[0]; dfs(0, 0); printf("%d", ans); return 0; }
标签:include 老年人 printf nbsp mes size pre i++ can
原文地址:https://www.cnblogs.com/cminus/p/11601064.html