forked from sameer2800/Lightoj-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1169-monkeys_on_twin_towers.cpp
80 lines (61 loc) · 1.28 KB
/
1169-monkeys_on_twin_towers.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
#include <bits/stdc++.h>
#define ll long long
#define MAX 100100
using namespace std;
ll a[1010], b[1010], crossa[1010], crossb[1010];
ll n;
ll dp[3][1010];
ll bottomup(int building, int floor)
{
if (floor == n - 1) {
if (building == 0) {
return a[floor];
} else {
return b[floor];
}
}
if (dp[building][floor])
return dp[building][floor];
ll temp = 0;
if (building == 0) {
temp = a[floor] + min(bottomup(building, floor + 1) , crossa[floor] + bottomup(1, floor + 1));
} else {
temp = b[floor] + min(bottomup(building, floor + 1) , crossb[floor] + bottomup(0, floor + 1));
}
dp[building][floor] = temp;
return temp;
}
ll twintowers()
{
memset(dp, 0, sizeof dp);
// building_no,floor_no
return min(bottomup(0, 0) , bottomup(1, 0) );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
ll i, j, k, m, t, cont;
cin >> t;
ll cases = t;
while (t--) {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
for (i = 0; i < n - 1; i++) {
cin >> crossa[i];
}
for (i = 0; i < n - 1; i++) {
cin >> crossb[i];
}
ll ans = twintowers();
cout << "Case " << cases - t << ": " << ans << endl;
}
return 0;
}