题解 | #最大序列和#简单dp
最大序列和
https://www.nowcoder.com/practice/df219d60a7af4171a981ef56bd597f7b
#include <iostream> using namespace std; long long num[1000000]; long long dp[1000000]; int main() { int N; while(scanf("%d", &N) != EOF){ for(int i = 0; i < N; i++){ scanf("%lld", &num[i]); } dp[0] = num[0]; long long max = dp[0]; for(int i = 1; i < N; i++){ if(num[i] > num[i] + dp[i - 1]){ dp[i] = num[i]; }else{ dp[i] = num[i] + dp[i - 1]; } max = max > dp[i] ? max : dp[i]; } printf("%lld\n", max); } } // 64 位输出请用 printf("%lld")