acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 包AC

    #include<bits/stdc++.h> using namespace std; const int maxn = 1e6+16; int n, tot, ans; int f[maxn]; class trie { public: int c[30]; int have; }; trie t[maxn]; void insert(string s) { int cur = 0; for (int i = 0; i < s.size(); i++) { int j = s[i] - 'a'; if (t[cur].c[j] == 0) { t[cur].c[j] = tot; } cur = t[cur].c[j]; } t[cur].have; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { string s; cin >> s; reverse(s.begin(), s.end()); insert(s); } for (int i = tot; i >= 0; i--) { f[i] = t[i].have; int maxa = 0, maxb = 0; for (int j = 0; j <= 'z' - 'a'; j++) { if (t[t[i].c[j]].have) { f[i]++; if (f[t[i].c[j]] - 1 > maxa) { maxb = maxa; maxa = f[t[i].c[j]] - 1; } else if (f[t[i].c[j]] - 1 > maxb) { maxb = f[t[i].c[j]] - 1; } } } f[i] += maxa; ans = max(ans, f[i] + maxb); } cout << ans << endl; return 0; }

    userId_undefined

    我

    倔强青铜
    1阅读
    0回复
    0点赞
首页