跳到正文

题解

题解:AT_abc416_c [ABC416C] Concat (X-th)

Genser约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年7月27日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 2 分钟

版本

  1. v1当前

看数据注意到 1≤n≤101 \le n \le 10,1≤k≤51 \le k \le 5,数据范围很小,所以直接 nkn^k 暴力搜索把所有可能的字符串求出来排序即可。

Code

C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define N 100010
using namespace std;
inline long long read()
{
	long  long x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
string p[N];
int cnt=0,n,m,k,vis[N];
struct node{
	string s;
}a[N];
void dfs(string x,int tep)
{
    if(tep==m+1)
    {
        a[++cnt].s+=x;
        return;
    }
    for(int i=1;i<=n;i++) dfs(x+p[i],tep+1);
	return;
}
int cmp(node a,node b)
{
	return a.s<b.s;
}
signed main(){
	n=read();m=read();k=read();
	for(int i=1;i<=n;i++) cin>>p[i];
	dfs("",1);
	sort(a+1,a+cnt+1,cmp);
	cout<<a[k].s<<endl;
    //for(int i=1;i<=cnt;i++) cout<<a[i].s<<endl;
	return 0;
}

原文