Cod sursa(job #2751341)

Utilizator andreea_07Andreea Georgescu andreea_07 Data 14 mai 2021 19:59:30
Problema Planeta Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("planeta.in");
ofstream fout("planeta.out");

long long  Arbore[35], n, k;

void f(int st,long long k,  int dr)
{int x;

for (int i = st; i <= dr ; i++)
{
    if (k > Arbore[i - st] * Arbore[dr - i])
        k -= Arbore[i - st] * Arbore[dr - i];
    else
    {
        fout<<i<<" ";

        f(st,  1 + (k - 1) / Arbore[dr - i],  i - 1);

        x = k % Arbore[dr - i];

        if (x == 0)
            x = Arbore[dr - i];

        f(i + 1,x, dr);
        break;
    }
}
}

int main()
{int i,j;
fin >> n >> k;
 Arbore[0] = 1;
 Arbore[1] = 1;
 for ( i = 2; i <= n; i++)
    for ( j = 0; j < i; j++)
        Arbore[i] += Arbore[i - j - 1] *Arbore[j] ;



f(1,k, n);
                return 0;
}