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
| #include <bits/stdc++.h> using namespace std; typedef long long ll;
const int N = 300; ll dp[N][N]; int a, b; ll k;
string find_kth(int a, int b, ll k){ if (a == 0) { return string(b, 'b'); } if (b == 0) { return string(a, 'a'); } if (k <= dp[a - 1][b]) { return string("a") + find_kth(a - 1, b, k); } else { return string("b") + find_kth(a, b-1, k - dp[a - 1][b]); } }
int main(){ cin >> a >> b >> k; dp[0][0] = 1; for (int i = 0; i <= a; i++) { for (int j = 0; j <= b; j++) { if (i > 0) { dp[i][j] += dp[i - 1][j]; } if (j > 0) { dp[i][j] += dp[i][j - 1]; } } } cout << find_kth(a, b, k) << endl;
return 0; }
|