This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
#define maxn 1000
using namespace std;
int dp[maxn];
int main() {
int n;
scanf("%d", &n);
int a[maxn];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
dp[0] = a[0];//边界 (结果总是确定的,动态规划总是从这些边界出发)
dp[i] = max(a[i], dp[i - 1] + a[i]);//递推式
//dp[i]存放以a[i]结尾的连续序列的最大和,需要遍历i得到最大的才是结果
int k = 0;
if (dp[i] > dp[k]) {
k = i;
printf("%d\n", dp[k]);
return 0;