# hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和

http://acm.hdu.edu.cn/showproblem.php?pid=1087

 1 #include<cstdio>
2 #include<cstring>
3 #include<iostream>
4 #include<algorithm>
5 #include<string>
6 using namespace std;
7 typedef long long ll;
8 int cases;
9 const int maxn = 1e5 + 100;
10 typedef long long ll;
11 int n;
12 int a[maxn], dp[maxn];//dp[i]表示以第i位结尾的最大上升序列和
13 //dp[i] = max(dp[i], a[i] + dp[j])如果j < i && a[j] < a[i]
14 int main()
15 {
16     while(cin >> n && n)
17     {
18         for(int i = 0; i < n; i++)
19         {
20             cin >> a[i];
21             dp[i] = a[i];
22         }
23         for(int i = 0; i < n; i++)
24         {
25             for(int j = 0; j < i; j++)
26             {
27                 if(a[j] < a[i])dp[i] = max(dp[i], a[i] + dp[j]);
28             }
29         }
30         int ans = dp[0];
31         for(int i = 1; i < n; i++)ans = max(ans, dp[i]);
32         cout<<ans<<endl;
33     }
34     return 0;
35 }

posted @ 2018-03-30 15:32  _努力努力再努力x  阅读(163)  评论(0编辑  收藏  举报