-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsubm.cpp
48 lines (42 loc) · 1011 Bytes
/
subm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# include <cstdio>
# include <algorithm>
# include <cstring>
# define NR 50
using namespace std;
int i,j,n,m,x,y,VV,ord,T;
int a[NR], var[NR];
void dinamica ()
{
int S=0;
// a[i] - numarul de moduri de a face submultimi care incep cu cifra i
for (i=n; i>=1; --i){
S+=a[i+2];
a[i]=1 + S;
}
}
int main ()
{
freopen ("subm.in", "r", stdin);
freopen ("subm.out", "w", stdout);
scanf ("%d", &n); dinamica ();
scanf ("%d", &T);
for (int t=1; t<=T; ++t) {
scanf ("%d", &ord);
if (ord==1) {printf ("1\n"); continue;}
memset(var, 0, sizeof(var));
VV=0; var[0]=-1;
while (ord) {
for (i=var[VV]+2; i<=n; ++i) {
if (ord > a[i]) ord-=a[i];
else {
var[++VV]=i; --ord;
break;
}
}
}
for (i=1; i<=VV; ++i)
printf ("%d ", var[i]);
printf ("\n");
}
return 0;
}