-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1256.cpp
More file actions
50 lines (49 loc) · 1.04 KB
/
1256.cpp
File metadata and controls
50 lines (49 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#define MAX 1000000001
using namespace std;
using ll = long long;
long long d[201][201];
int comb(int n,int m){
if(d[n][m]>0)return d[n][m];
if(n==m||m==0){
return d[n][m]=1;
}
d[n][m]=comb(n-1,m)+comb(n-1,m-1);
return d[n][m]=d[n][m]>=MAX?MAX:d[n][m];
}
string go(int n,int m,int k){
if(comb(n+m,n)<=k){
return "-1";
}
long long mid = comb(n+m-1,n-1);
if(n==1||m==1){
string ret="";
vector<char> va(n,'a');
vector<char> vz(m,'z');
va.insert(va.end(),vz.begin(),vz.end());
do{
if(k==0){
break;
}
k--;
}while(next_permutation(va.begin(),va.end()));
for(int i=0;i<va.size();i++){
ret+=va[i];
}
return ret;
}
if(k>=mid){
return "z"+go(n,m-1,k-mid);
}else{
return "a"+go(n-1,m,k);
}
}
int main(){
int n,m,k;
cin>>n>>m>>k;
cout<<go(n,m,k-1);
}