forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
78 lines (68 loc) · 1.77 KB
/
E.cpp
File metadata and controls
78 lines (68 loc) · 1.77 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
#include <bits/stdc++.h>
using namespace std;
const int BASE = int(1e9) + 7, K = 25, oo = 27081993;
struct Triple
{
int i, j, s;
};
long long f[33][33][33], g[33][33][33];
vector <Triple> good;
long long calcWays(int a, int b, int c)
{
long long res = 0;
memset(g, 0, sizeof g);
for (auto u : good)
for (auto v : good)
if (u.i + v.i < a && u.s + v.s <= c)
{
g[u.j][v.j][u.s + v.s] += f[u.i][u.j][u.s] * f[v.i][v.j][v.s];
g[u.j][v.j][u.s + v.s] %= BASE;
}
for (int i = 0; i <= K; i++)
for (int j = 0; j <= K; j++)
for (int k = 0; k <= c; k++)
for (int ii = 0; ii <= K; ii++)
for (int jj = 0; jj <= K; jj++)
if (i + ii < b && j + jj < b)
res = (res + g[i][j][k] * g[ii][jj][c - k]) % BASE;
return res;
}
int main()
{
freopen("expedition.in", "r", stdin);
freopen("expedition.out", "w", stdout);
int n;
cin >> n;
f[0][0][0] = 1;
good.push_back({0, 0, 0});
for (int i = 1; i <= K; i++)
{
f[1][i][i] = 1;
good.push_back({1, i, i});
}
for (int i = 2; i <= K; i++)
for (int j = 1; j <= K; j++)
for (int s = j; s <= K; s++)
{
for (int jj = j; jj <= K; jj++)
f[i][j][s] = (f[i][j][s] + f[i - 1][jj][s - j]) % BASE;
if (f[i][j][s])
good.push_back({i, j, s});
}
int ans = oo;
long long ways = 0;
for (int i = 1; i <= K; i++)
for (int j = i;; j++)
if (i * j >= n)
{
if (i + j <= ans)
{
long long cur = calcWays(i, j, i * j - n) * (i == j ? 1 : 2);
if (i + j == ans) ways += cur;
else ways = cur;
ans = i + j;
}
break;
}
cout << ways << endl;
}