Skip to content

Commit 4dbe216

Browse files
committed
20190501
1 parent 1b965ab commit 4dbe216

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

MaxSubSum_dp.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
const int maxn = 1005;
5+
6+
long long dp[maxn];
7+
long long a[maxn];
8+
long long n;
9+
10+
int main()
11+
{
12+
cin >> n;
13+
for (int i = 1; i <= n; i++)
14+
{
15+
cin >> a[i];
16+
dp[i] = a[i];
17+
}
18+
for (int i = 1; i <= n; i++)
19+
{
20+
dp[i] = max(dp[i], dp[i - 1] + a[i]);
21+
}
22+
long long ans = 0;
23+
for (int i = 1; i <= n; i++)
24+
ans = max(ans, dp[i]);
25+
cout << ans << endl;
26+
system("pause");
27+
return 0;
28+
}

0 commit comments

Comments
 (0)