int n; int* dp; string* strs; intcommon(string a, string b){ int res = 0; int len = (a.size() < b.size()) ? a.size() : b.size(); for (size_t i = 0; i < len; i++) { if (a[i] == b[i]) { res++; } else { return0; } } return res; }
intmain(){ ios::sync_with_stdio(0); cin >> n; strs = new string[n + 1]; dp = newint[n + 1]; memset(dp, 0, sizeof(int) * (n + 1)); int ans = 1; for (int i = 1; i <= n; i++) { cin >> strs[i]; } dp[1] = 1; for (int i = 2; i <= n; i++) { for (int j = i; j >= 1; j--) { if (strs[i].find(strs[j]) == 0) { dp[i] = max(dp[i], dp[j] + 1); ans = max(ans, dp[i]); } } } for (int i = 0; i < n; i++) { cout << dp[i + 1] << ' '; }