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
71 lines (64 loc) · 2.08 KB
/
E.cpp
File metadata and controls
71 lines (64 loc) · 2.08 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
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
int a[22];
int res[20] = {
1,2,3,5,8,14,25,45,85,162,310,595,1165,2285,4485,8808,17306,34302,68009,134853
};
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
freopen("chipmunks.in", "r", stdin);
freopen("chipmunks.out", "w", stdout);
int n;
while (cin >> n) {
cout << res[n-1] << endl;
}
return 0;
set< pair<int,int> > all;
FOR(i,1,20) {
DEBUG(i);
if (i <= 3) {
a[i] = i;
}
else {
a[i] = a[i-1] + 1;
while (true) {
bool found = false;
REP(mask,1<<(i-1)) {
int cnt = __builtin_popcount(mask) + 1;
int sum = a[i];
REP(b,i-1) if (mask & (1<<b)) {
sum += a[b+1];
}
if (all.find(make_pair(cnt, sum)) != all.end()) {
found = true;
break;
}
}
if (found) ++a[i];
else break;
}
}
DEBUG(a[i]);
// add all sets with this bit on
REP(mask,1<<(i-1)) {
int cnt = __builtin_popcount(mask) + 1;
int sum = a[i];
REP(b,i-1) if (mask & (1<<b)) {
sum += a[b+1];
}
all.insert(make_pair(cnt, sum));
}
// for(auto p : all) cout << p.first << ' ' << p.second << " "; cout << endl;
}
FOR(i,1,20) cout << a[i] << ',';
cout << endl;
}