void solve (){
int N; cin >> N;
vector <ll> vec(N);
for (auto &to:vec) cin >> to;
ll sum = 0;
for (auto to:vec) if (to > 0) sum += to;
cout << sum << '\n';
}
int N;
vector <ll> vec;
ll f (int index, ll tmp, bool last){
if (index == 0){
return max(f(index+1, 0, 0), f(index+1, vec[index], 1));
}
if (index == N-1){ // to the end
return (last) ? (tmp) : max(tmp, tmp+vec[index]);
}
return (last) ? (f(index+1, tmp, 0)) :
max(f(index+1, tmp+vec[index], 1), f(index+1, tmp, 0));
}
void solve (){
cin >> N;
vec.resize(N);
for (auto &to:vec) cin >> to;
cout << f(0, 0, 0) << '\n';
}
我都已經明示你是 DP,而且不用考慮 vec[i+1] 了
你在做後面的項目時,他自然會考慮到 vec[i]
所以其實你轉移式只需要在意左邊
不需要重複考慮右邊的東西
2023 Academic
2022 Academic
2023 Acedamic
比賽時長:168 小時
題目數:5 + 10 + 5 = 20
Problems per day:2.857
Tatal submissions:1489
Submissions per day:212.714
第一名翻盤次數:15
2022 Acedamic
比賽時長:72 小時
題目數:2 + 5 + 5 = 12
Problems per day:4
Tatal submissions:729
Submissions per day:243
第一名翻盤次數:0