K-Box_2023牛客暑期多校训练营2 (nowcoder.com)
#include<bits/stdc++.h> #define int long long using namespace std; typedef pair<int, int> PII; const int N = 1e6 + 110, mod = 1e9 + 7; int a[N]; int st[N]; int f[N][2]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> st[i]; for (int i = 1; i <= n; i++) { f[i][0] = max(f[i - 1][1], f[i - 1][0]); if (st[i]) { f[i + 1][1] = max(f[i][0], f[i][1]) + a[i + 1]; f[i][1] = max(f[i - 1][0] + a[i], f[i - 1][1] + a[i]); f[i][0] = max(f[i - 1][0] + a[i - 1], f[i][0]); } } cout << max(f[n][1], f[n][0]) << "\n"; return 0; }
标签:int,nullptr,cin,long,经典,tie,dp From: https://www.cnblogs.com/spiderflower/p/17852366.html