题意:有两座塔,有n层,每层有一个水果,吃掉水果的时间分别时a[i], b[i],从i到i + 1层有两种方式,一种是直接上去,不消耗时间,另一种是跳到另一座塔,消耗u[i]或v[i]的时间。要跳到最高层,求最小时间。
题解:每层有两种决策。
#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define ll long long
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i)
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Min(a, b) a = min(a, b)
#define Max(a, b) a = max(a, b)
const int maxn = 1e3 + 7;
const int maxm = 5e3 + 7;
int T;
int kase;
int n;
int a[maxn];
int b[maxn];
int u[maxn];
int v[maxn];
int dp[maxn][2];
int solve(){
dp[0][0] = a[0], dp[0][1] = b[0];
REP(i, 1, n){
dp[i][0] = min(dp[i-1][0], dp[i-1][1] + v[i-1]) + a[i];
dp[i][1] = min(dp[i-1][1], dp[i-1][0] + u[i-1]) + b[i];
}
return min(dp[n-1][0], dp[n-1][1]);
}
int main(){
#ifdef ac
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
scanf("%d", &T);
while(T--){
scanf("%d", &n);
REP(i, 0, n) scanf("%d", &a[i]);
REP(i, 0, n) scanf("%d", &b[i]);
REP(i, 0, n-1) scanf("%d", &u[i]);
REP(i, 0, n-1) scanf("%d", &v[i]);
printf("Case %d: %d\n", ++ kase, solve());
}
return 0;
}