Problem:
Kth Sentence

A student, Kita_masa, is taking an English examination.
In this examination, he has to write a sentence of length m.

Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K-th sentence among the candidates sorted in lexicographic order.
He believes that it must be the correct sentence because K is today's lucky number for him.

Each word may be used multiple times (or it's also fine not to use it at all) and the sentence does not contain any extra character between words.
Two sentences are considered different if the order of the words are different even if the concatenation resulted in the same string.

Input

The first line contains three integers n (1 \leq n \leq 100), m (1 \leq m \leq 2000) and K (1 \leq K \leq 10^{18}), separated by a single space.
Each of the following n lines contains a word that Kita_masa knows.
The length of each word is between 1 and 200, inclusive, and the words contain only lowercase letters.
You may assume all the words given are distinct.

Output

Print the K-th (1-based) sentence of length m in lexicographic order.
If there is no such a sentence, print "-".

Sample Input 1

2 10 2
hello
world

Output for the Sample Input 1

helloworld

Sample Input 2

3 3 6
a
aa
b

Output for the Sample Input 2

aba

Sample Input 3

2 59 1000000000000000000
a
b

Output for the Sample Input 3

-

Solution in C++ (judge verdict: Accepted)

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,M;
ll dp[2005];
ll dp2[105][205],work[105][205];
ll next_ch[26];
ll K;
ll len[105];
double tmp_K;
char word[105][205];

void add(ll &A,ll B){
	A = min(K,A+B);
}

ll mult(ll A,ll B){

	double tmp_A = A,tmp_B = B;

	if(tmp_A*tmp_B > tmp_K){

		return K;

	}else{

		return A*B;
	}
}

int main(){

	scanf("%d %d %lld",&N,&M,&K);

	tmp_K = (double)K;

	int length;

	for(int i = 0; i < N; i++){

		scanf("%s",word[i]);

		for(length = 0; word[i][length] != '\0'; length++);

		len[i] = length;
	}

	dp[0] = 1;
	for(int i = 1; i <= M; i++){
		dp[i] = 0;
	}

	for(int left = 0; left <= M-1; left++){
		for(int i = 0; i < N; i++){

			if(left+len[i] > M)continue;

			add(dp[left+len[i]],dp[left]);
		}
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < len[i]; k++){
			dp2[i][k+1] = 0;
		}
	}

	bool FLG = false;

	for(int i = 0; i < N; i++){
		if(len[i] <= M){
			dp2[i][len[i]-1] = 1;
			FLG = true;
			break;
		}
	}

	if(!FLG){
		printf("-\n");
		return 0;
	}

	queue<char> ANS;
	ll tmp,sum;
	char tmp_ch;

	for(int i = 0; i < M; i++){

		for(int ch = 0; ch < 26; ch++){

			next_ch[ch] = 0;
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){

				if(k == len[a]-1){

					for(int b = 0; b < N; b++){

						add(next_ch[word[b][0]-'a'],mult(dp2[a][k],dp[M-i-len[b]]));
					}

				}else{

					add(next_ch[word[a][k+1]-'a'],mult(dp2[a][k],dp[M-i-len[a]+k+1]));
				}
			}
		}

		sum = 0;
		tmp_ch = '@';

		for(int k = 0; k < 26; k++){

			tmp = sum;

			sum += next_ch[k];

			if(sum >= K){
				tmp_ch = 'a'+k;
				ANS.push(tmp_ch);
				K -= tmp;
				break;
			}
		}

		if(tmp_ch == '@'){

			printf("-\n");
			return 0;
		}

		for(int a = 0; a < N; a++){
			for(int b = 0; b < len[a]; b++){
				work[a][b] = 0;
			}
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){

				if(k == len[a]-1){

					for(int b = 0; b < N; b++){
						if(word[b][0] != tmp_ch)continue;
						add(work[b][0],dp2[a][k]);
					}

				}else{

					if(word[a][k+1] != tmp_ch)continue;
					add(work[a][k+1],dp2[a][k]);
				}
			}
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){
				dp2[a][k] = work[a][k];
			}
		}
	}

	while(!ANS.empty()){
		printf("%c",ANS.front());
		ANS.pop();
	}

	printf("\n");

	return 0;
}