-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
151 lines (133 loc) · 1.61 KB
/
main.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
template<uint N, uint Base>
struct FragImpl;
template<uint N>
struct Capacity
{
enum
{
value = N - 1 + Capacity<N-1>::value
};
};
template<>
struct Capacity<0>
{
enum
{
value = 0
};
};
template<uint N, uint Step>
struct Loop
{
enum
{
value = FragImpl<N-Step, Step>::value + Loop<N, Step-1>::value
};
};
template<uint N>
struct Loop<N, 0>
{
enum
{
value = FragImpl<N, 0>::value
};
};
template<uint A, uint B>
struct MIN
{
enum
{
value = (A < B) ? A : B
};
};
template<uint N, uint Base, bool Condition>
struct Check
{
enum
{
value = 0
};
};
template<uint N, uint Base>
struct Check<N, Base, true>
{
enum
{
value = Loop<N, MIN<N, Base-1>::value>::value
};
};
template<uint N, uint Base>
struct FragImpl
{
enum
{
value = Check<N, Base, N <= Capacity<Base>::value>::value
};
};
template<>
struct FragImpl<0, 0>
{
enum
{
value = 1
};
};
template<uint N>
struct Frag
{
enum
{
value = FragImpl<N, N+1>::value
};
};
uint fragImpl(uint n, uint base)
{
switch(n)
{
case 0:
case 1:
case 2:
return 1;
case 3:
return (base > 3) ? 2 : 1;
default:
uint k = ceil(-0.5+sqrt(1+8*n)/2);
uint res = 0;
for (uint i = k; i <= n && base > i; ++i)
res += fragImpl(n-i, i);
return res;
}
return n;
}
uint frag(uint n)
{
return fragImpl(n, n+1);
}
template<uint N>
uint f(uint n)
{
switch(n)
{
case N:
return Frag<N>::value;
default:
return f<N-1>(n);
}
}
template<>
uint f<0>(uint n)
{
return Frag<0>::value;
}
int main()
{
uint n;
cin >> n;
cout << f<150>(n) << endl;
return 0;
}