题目链接:http://codeforces.com/contest/358/problem/D
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int maxn = 3005; int a[maxn],b[maxn],c[maxn]; int dp1[maxn],dp2[maxn]; int n; int main() { //freopen("E:\acm\input.txt","r",stdin); cin>>n; for(int i=1; i<=n; i++) cin>>a[i]; for(int i=1; i<=n; i++) cin>>b[i]; for(int i=1; i<=n; i++) cin>>c[i]; dp2[n] = b[n]; dp1[n] = a[n]; for(int i=n-1; i>=1; i--) { dp1[i] = max(a[i]+dp2[i+1],b[i]+dp1[i+1]); dp2[i] = max(b[i]+dp2[i+1],c[i]+dp1[i+1]); } printf("%d ",dp1[1]); }