首页 > 其他 > 详细

hdu 1087 最大递增子序列

时间:2017-10-04 13:54:54      阅读:271      评论:0      收藏:0      [点我收藏+]
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int  maxn = 2e5 + 100;
const int  maxm = 300;
//next_permutation
//priority_queue<int, vector<int>, greater<int>> que;
ll dp[1005];
ll num[1005];
int main()
{
        //freopen("bonuses.in", "r", stdin);
        //freopen("out.txt", "w", stdout);
        int n;
        while (cin >> n && n)
        {
                mem(dp, 0);
                ll ans = 0;
                for (int i = 1; i <= n; i++)
                {
                        cin >> num[i];
                }
                ans = dp[1] = num[1];
                for (int i = 2; i <= n; i++)
                {
                        dp[i]=num[i];
                        for (int j = 1; j < i; j++)
                        {
                                if (num[j] < num[i])
                                {
                                        dp[i] = max(dp[i], dp[j] + num[i]);
                                }
                        }
                        ans = max(ans, dp[i]);
                }
                cout << ans << endl;
        }
}

 

hdu 1087 最大递增子序列

原文:http://www.cnblogs.com/Aragaki/p/7625324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!