https://codeforces.com/contest/1195/problem/C
题解:一维线性dp,注意状态转移方程,0是取第一行,1是取第二行
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1000000;
typedef long long ll;
int n;
ll a[maxn];
ll b[maxn];
ll dp[2][1000005];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
dp[0][0]=0;
dp[1][0]=0;
for(int i=1;i<=n;i++){
dp[0][i]=max(a[i]+dp[1][i-1],dp[0][i-1]);//第一行开始取
dp[1][i]=max(b[i]+dp[0][i-1],dp[1][i-1]);//第二行开始取
}
cout<<max(dp[0][n],dp[1][n])<<endl;
return 0;
}