-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathD.cpp
114 lines (90 loc) · 2.09 KB
/
D.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//AshrafSustS19
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
ll MOD = 998244353;
//memorization for factorial
vector<ll> fac(2000001, 0), facinv(2000001, 0);
ll power(ll num, ll pow)
{
ll res = 1;
num = num % MOD;
while (pow > 0)
{
if (pow & 1)
res = (res * num) % MOD;
pow >>= 1;
num = (num * num) % MOD;
}
return res;
}
ll modInverse(ll num)
{
return power(num, MOD - 2);
}
ll getFac(ll n)
{
if (n == 0) return 1;
if (fac[n] != 0)
return fac[n];
else
return fac[n] = (n * getFac(n - 1)) % MOD;
}
ll getFacInv(ll n){
if (n == 0) return 1;
if (facinv[n] != 0)
return facinv[n];
else
return facinv[n] = modInverse(getFac(n));
}
ll ncr(ll n, ll r)
{
if (n < r || r < 0 || n < 0)
return 0;
if (r == 0)
return 1;
return (getFac(n) * ((getFacInv(r) * getFacInv(n - r)) % MOD)) % MOD;
}
ll N, n;
vector<vector<ll>> MEM;
vector<ll> lp2((1ll << 20) + 5, -1);
ll getP2(ll p){
if (lp2[p] != -1){
return lp2[p];
}
if (p == 0){
return lp2[p] = 1;
}
return lp2[p] = (getP2(p - 1) * 2) % MOD;
}
ll dp(ll ind, ll cnt){
if (ind > n){
return (cnt == N + 1);
}
if (MEM[cnt][ind] != -1){
return MEM[cnt][ind];
}
ll p1 = 0, p2 = 0;
ll totnd = (1ll << cnt);
if (ind >= totnd){
ll cnd = (1ll << (cnt - 1)) - 1;
ll av = ind - totnd + cnd;
ll mul = getFac(cnd + 1) * ncr(av, cnd) % MOD;
// ll mul = getFac(cnd + 1);
mul = (mul * 2) % MOD;
p1 = dp(ind + 1, cnt + 1) * mul % MOD;
}
p2 = dp(ind + 1, cnt);
return MEM[cnt][ind] = (p1 + p2) % MOD;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
n = 1ll << N;
MEM.resize(N + 2, vector<ll> (n + 1, -1));
for (int i = 0; i < n; i++){
ll res = dp(n - i + 1, 1);
cout << res << "\n";
}
}