比赛 2026.1.3 评测结果 AAAAATATAAAAAAAAAATW
题目名称 字符串游戲 最终得分 80
用户昵称 LikableP 运行时间 4.190 s
代码语言 C++ 内存使用 3.66 MiB
提交时间 2026-01-03 11:46:55
显示代码纯文本
#include <iostream>
#include <algorithm>
#include <ctime>

const int MAXN = 210;

int n, m, k;
std::string A;
std::string B[MAXN];
std::size_t ans = 0xffffffffffffffff;

void dfs(std::string str, int step) {
  ans = std::min(ans, str.length());
  if (step > k) return ;
  for (int i = 1; i <= m; ++i) {
    std::size_t pos = str.find(B[i]);
    if (pos == std::string::npos) continue;
    std::string newstr = str;
    newstr.erase(pos, B[i].length());
    dfs(newstr, step + 1);
  }
}

int main() {
  #ifdef LOCAL
    freopen("!input.in", "r", stdin);
    freopen("!output.out", "w", stdout);
  #else
    freopen("string.in", "r", stdin);
    freopen("string.out", "w", stdout);
  #endif
  std::cin.tie(0)->sync_with_stdio(false), std::cout.tie(0);
  std::cin >> n >> m >> k;
  std::cin >> A;
  for (int i = 1; i <= m; ++i) {
    std::cin >> B[i];
  }

  std::sort(B + 1, B + m + 1, [](std::string x, std::string y) {
    return x.length() > y.length();
  });

  if (k == 1) {
    for (int i = 1; i <= m; ++i) {
      if (A.find(B[i]) != std::string::npos) {
        std::cout << A.length() - B[i].length() << '\n';
        break;
      }
    }
    return 0;
  } 

  dfs(A, 1);

  std::cout << ans << '\n';
  return 0;
}