-
Notifications
You must be signed in to change notification settings - Fork 1
/
QBSELECT.cpp
74 lines (66 loc) · 1.65 KB
/
QBSELECT.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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#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 FILL(a, v, n) for(int i = 0, _n = (n); i < _n; ++i) a[i] = v
#define pr(x) cout << #x << " = " << x << endl
#define pra(a, n) REP(i, 0, n) cout << #a << "[" << i << "] = " << a[i] << " "; cout << "\n"
#define sz(x) (int)(x.size())
#define endl "\n"
#define newline cout << "\n"
#define getBit(num, ith) ((num >> (ith)) & 1)
#define toggleBit(num, ith) (num ^ (1>>(ith)))
#define OffBit(num, ith) (num & (~(1<<(ith))))
#define OnBit(num, ith) (num | (1<<(ith)))
using namespace std;
const int N = 10005;
const int INF = 1E9;
int state[8] = {0, 1, 2, 4, 8, 5, 9, 10};
int dp[N][20];
int m[5][N];
inline int getSum(int c, int mask) {
int res = 0;
FOR(i, 1, 4) {
if(getBit(mask, i-1)) res += m[i][c];
}
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
#ifndef Home
freopen ("input.txt", "r", stdin);
#endif
int n;
cin >> n;
bool pig = true;
int vmax = INT_MIN;
FOR(i, 1, 4) {
FOR(j, 1, n) {
cin >> m[i][j];
if(m[i][j] > 0) pig = false;
vmax = max(vmax, m[i][j]);
}
}
if(pig) {
cout << vmax << endl;
return 0;
}
REP(i, 0, 8) {
dp[1][state[i]] = max(0, getSum(1, state[i]));
}
FOR(c, 2, n) {
REP(i, 0, 8) {
dp[c][state[i]] = 0;
REP(j, 0, 8) {
if(state[i] & state[j]) continue;
dp[c][state[i]] = max(dp[c][state[i]], dp[c-1][state[j]] + getSum(c, state[i]));
}
}
}
int ans = 0;
REP(i, 0, 8) {
ans = max(ans, dp[n][state[i]]);
}
cout << ans << endl;
return newline, 0;
}