Pagini recente » Cod sursa (job #90416) | Cod sursa (job #2132657) | Cod sursa (job #2714477) | Cod sursa (job #2050142) | Cod sursa (job #2899234)
#include <fstream>
#define NMAX 31
using namespace std;
ifstream fin("planeta.in");
ofstream fout("planeta.out");
int N, K, x[NMAX];
void tree(int st, int dr, int k)
{
int i, dif;
for(i = st; i <= dr && k > x[i - st] * x[dr - st]; ++i)
k -= x[i - st] * x[dr - i];
fout<<i<<" ";
if(i > st)
tree(st, i - 1, 1 + (k - 1) / x[dr - i]);
if(k % x[dr - i] == 0)
dif = x[dr - i];
else
dif = k % x[dr - i];
if(i < dr)
tree(i + 1, dr, dif);
}
int main()
{
fin>>N>>K;
x[0] = x[1] = 1;
for(int i = 2; i <= N; ++i)
for(int j = 1; j <= i; ++j)
x[i] += x[j - 1] * x[i - j];
tree(1, N, K);
return 0;
}