Cod sursa(job #1536615)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 26 noiembrie 2015 14:18:38
Problema Planeta Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<fstream>
using namespace std;
int n, i, x;
long long k, d[40];
ifstream fin("planeta.in");
ofstream fout("planeta.out");
void f(int n, long long k, int start){
    if(n != 0){
        long long sum = 0;
        for(int x = 1; x <= n; x++){
            if(sum + d[x - 1] * d[n - x] < k){
                sum += d[x - 1] * d[n - x];
            }
            else{
                fout<< x + start -1 <<" ";
                f(x - 1, (k - sum) / d[n - x], start);
                f(n - x, (k - sum) % d[n - x], start + x);
                break;
            }
        }
    }
}
int main(){
    fin>> n >> k;
    d[0] = d[1] = 1;
    for(i = 2; i <= n; i++){
        for(x = 1; x <= i; x++){
            d[i] = d[i] +  d[x - 1] * d[i - x];
        }
    }
    f(n, k, 1);
    return 0;
}