poj3187

简单题

View Code
#include <iostream>
#include
<cstdlib>
#include
<cstring>
#include
<cstdio>
#include
<algorithm>
using namespace std;

#define maxn 15

int n, f[maxn], g[maxn], sum;

int cal()
{
int ret = 0;
for (int i = 0; i < n; i++)
ret
+= f[i] * g[i];
return ret;
}

int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d", &n, &sum);
memset(f,
0, sizeof(f));
f[
0] = 1;
for (int i = 1; i < n; i++)
{
for (int j = i; j >= 1; j--)
f[j]
= f[j] + f[j - 1];
}
for (int i = 0; i < n; i++)
g[i]
= i + 1;
while (sum != cal())
next_permutation(g, g
+ n);
printf(
"%d", g[0]);
for (int i = 1; i < n; i++)
printf(
" %d", g[i]);
putchar(
'\n');
return 0;
}
posted @ 2011-09-16 17:03  金海峰  阅读(261)  评论(0编辑  收藏  举报