-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy path12.5.cpp
More file actions
37 lines (32 loc) · 894 Bytes
/
12.5.cpp
File metadata and controls
37 lines (32 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* 题目名称:最大上升子序列和
* 题目来源:北京大学复试上机题
* 题目链接:http://t.cn/AiYNAGD3
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 1000 + 10;
int arr[MAXN];
int dp[MAXN];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
int answer = 0;
for (int i = 0; i < n; ++i) {
dp[i] = arr[i]; //初始化为arr[i]
for (int j = 0; j < i; ++j) {
if (arr[j] < arr[i]) {
dp[i] = max(dp[i], dp[j] + arr[i]);
}
}
answer = max(answer, dp[i]); //dp数组的最大值
}
printf("%d\n", answer);
}
return 0;
}