fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n,m,k;
  6. long long dp[105][105];
  7.  
  8. int main(){
  9. cin >> n >> m >> k;
  10.  
  11. for(int i=0;i<=100;i++){
  12. dp[i][0] = 1;
  13. dp[0][i] = 1;
  14. }
  15.  
  16. for(int i=1;i<=100;i++){
  17. for(int j=1;j<=100;j++){
  18. if(dp[i][j]==0){
  19. dp[i][j] = dp[i-1][j] + dp[i][j-1];
  20. }
  21. }
  22. }
  23. if (dp[n][m]<k){
  24. cout << -1 << endl;
  25. return 0;
  26. }
  27.  
  28.  
  29. while(n>0 || m>0){
  30.  
  31. // cout << "\nn: " << n << " m: " << m <<" k: "<< k << " | ";
  32. // cout << "dp[n][m]: " << dp[n][m] << endl;
  33. if(n>0 && dp[n-1][m]>=k){
  34.  
  35. cout << 'a' ;
  36. n--;
  37.  
  38. }
  39. else{
  40. cout << 'z';
  41. if(n>0) k -= dp[n-1][m];
  42. m--;
  43.  
  44. }
  45. }
  46. cout << endl;
  47. return 0;
  48. }
  49.  
  50.  
Success #stdin #stdout 0.01s 5280KB
stdin
7 4 47
stdout
aaazazaazaz