hdu 1087 最大递增子序列和
#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; } }