Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <vector>
- #include <numeric>
- #define int int64_t
- const int kN = 10001;
- int f[kN][kN];
- int calc(int n, int m) {
- if (m == 0) {
- if (n) {
- return 0;
- } else {
- return 1;
- }
- }
- if (!f[n][m]) {
- for (int i = 0; i <= n; i++) {
- f[n][m] += calc(n - i, m - 1);
- if (f[n][m] > std::numeric_limits<int32_t>::max()) {
- f[n][m] = std::numeric_limits<int32_t>::max();
- break;
- }
- }
- }
- return f[n][m];
- }
- void calculate(int n, int m, int k, std::vector<int> &v) {
- if (m == 0) {
- for (auto i : v) {
- std::cout << i << ' ';
- }
- return;
- }
- for (int i = n; i >= 0; i--) {
- int cnt = calc(n - i, m - 1);
- if (k >= cnt) {
- k -= cnt;
- } else {
- v.push_back(i);
- calculate(n - i, m - 1, k, v);
- return;
- }
- }
- }
- int32_t main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- int n, m, k;
- std::cin >> n >> m >> k;
- std::vector<int> v;
- calculate(n, m, k - 1, v);
- }
Advertisement
Add Comment
Please, Sign In to add comment