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

· · 题解

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

Code

#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;
}