# hdu2062 Subset sequence----递推

http://acm.hdu.edu.cn/showproblem.php?pid=2062

1
1    2
1    2    3
1    3
1    3    2
2
2    1
2    1    3
2    3
2    3    1
3
3    1
3    1    2
3    2
3    2    1

 1 #include<cstdio>
2 #include<cstring>
3 #include<iostream>
4 #include<algorithm>
5 #include<string>
6 using namespace std;
7 typedef long long ll;
8 int cases;
9 const int maxn = 1e5 + 100;
10 typedef long long ll;
11 ll n, m, a[30];
12 void init()
13 {
14     a[1] = 1;
15     for(ll i = 2; i < 21; i++)a[i] = i * (a[i - 1] + 1);
16     //for(int i = 1; i <= 20; i++)cout<<a[i]<<endl;
17 }
18 int main()
19 {
20     init();
21     while(cin >> n >> m)
22     {
23         int b[30], ans[30], tot = 0;
24         for(int i = 1; i <= n; i++)b[i] = i;
25         while(m > 0)
26         {
27             int c = (m + a[n - 1]) / (a[n - 1] + 1);
28             //cout<<m << " "<<c<<" "<< n<<endl;
29             ans[tot++] = b[c];
30             n--;
31             for(int i = c; i <= n; i++)b[i] = b[i + 1];
32             m -= (c - 1) * (a[n] + 1);
33             m--;
34             if(m <= 0)break;
35
36         }
37         cout<<ans[0];
38         for(int i = 1; i < tot; i++)cout<<" "<<ans[i];
39         cout<<endl;
40     }
41 }

posted @ 2018-03-30 15:07  _努力努力再努力x  阅读(199)  评论(0编辑  收藏  举报