-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0618.cpp
More file actions
129 lines (91 loc) · 1.92 KB
/
0618.cpp
File metadata and controls
129 lines (91 loc) · 1.92 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// https://acmp.ru/index.asp?main=task&id_task=618
// integer partitions + Young diagrams + DP + branch&bound + prefix sums
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100;
int n;
ll p[N + 1][N + 1];
ll c[N + 2][N + 1];
ll s[N + 2][N + 2];
int v[N + 1];
int bv[N + 1];
int vc;
int bvc;
ll ba;
ll ub(int r, int l, int d)
{
ll z = 0;
for (int i = 0; i <= l; ++i) z += c[d][i] * p[r][i];
return z - 1;
}
void go(int r, int l, int d)
{
ll z = ub(r, l, d);
if (z <= ba) return;
if (r == 0)
{
ba = z;
bvc = vc;
for (int i = 0; i < vc; ++i) bv[i] = v[i];
return;
}
s[d][l + 1] = 0;
for (int i = l; i >= 0; --i) s[d][i] = s[d][i + 1] + c[d][i];
int m = min(l, r);
for (int x = m; x >= 1; --x)
{
ll z2 = 0;
for (int y = 0; y <= x; ++y)
{
c[d + 1][y] = s[d][y];
z2 += c[d + 1][y] * p[r - x][y];
}
if (z2 - 1 <= ba)
continue;
v[vc++] = x;
go(r - x, x, d + 1);
--vc;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ll e[N + 1][N + 1] = {};
ll dp[N + 1] = {};
dp[0] = 1;
for (int m = 0; m <= n; ++m) e[0][m] = 1;
for (int m = 1; m <= n; ++m)
{
for (int i = m; i <= n; ++i) dp[i] += dp[i - m];
for (int i = 0; i <= n; ++i) e[i][m] = dp[i];
}
for (int m = 0; m <= n; ++m)
{
ll z = 0;
for (int i = 0; i <= n; ++i)
{
z += e[i][m];
p[i][m] = z;
}
}
ba = 0;
bvc = 0;
for (int x = n; x >= 1; --x)
{
for (int i = 0; i <= x; ++i) c[1][i] = 1;
vc = 1;
v[0] = x;
go(n - x, x, 1);
}
cout << ba << '\n';
for (int i = 0; i < bvc; ++i)
{
if (i) cout << ' ';
cout << bv[i];
}
cout << '\n';
return 0;
}