比赛 2026.1.3 评测结果 AAAAATATAAAAAATAAATW
题目名称 字符串游戲 最终得分 75
用户昵称 梦那边的美好CE 运行时间 4.746 s
代码语言 C++ 内存使用 3.63 MiB
提交时间 2026-01-03 10:58:34
显示代码纯文本
#include<bits/stdc++.h>
#define N 222
#define int long long
using namespace std;

inline void read(int &x) {bool neg = false;x = 0;char ch = 0;while (ch < '0' || ch > '9') {if (ch == '-') neg = true;ch = getchar();}if (neg) {while (ch >= '0' && ch <= '9') {x = x * 10 + ('0' - ch);ch = getchar();}} else {while (ch >= '0' && ch <= '9') {x = x * 10 + (ch - '0');ch = getchar();}}return;}

template <typename T> inline void write(T x) {if (x < 0) x = -x, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + 48);}

int n,m,k,vis[N];
string A,B[N];

bool cmp(string s1,string s2){
	return s1.length()>s2.length();
}

int ans=0;
void dfs(int deep){
	// cout<<A<<" "<<deep<<"\n";
	if(deep>k)return;
	ans=min(ans,(int)A.length());
	for(int i=1;i<=m;i++){
		int pos=A.find(B[i]);
		if(pos!=string::npos){
			A.erase(pos,B[i].length());
			dfs(deep+1);
			A.insert(pos,B[i]);
		}
	}
	return;
}

signed main(){
	freopen("string.in","r",stdin);freopen("string.out","w",stdout);
	read(n);read(m);read(k);
	cin>>A;
	for(int i=1;i<=m;i++)cin>>B[i];
	sort(B+1,B+m+1,cmp);
	if(k==1){
		for(int i=1;i<=m;i++){
			if(A.find(B[i])==string::npos){
				continue;
			}else{
				write(A.length()-B[i].length());
				return 0;
			}
		}
		write(A.length()); 
	}else{
		ans=A.length();
		dfs(0);
		write(ans);
	}
	return 0;
}