Super Jumping! Jumping! Jumping!(dp)

发布于 2020-10-17  0 次阅读


题目大意:

Super Jumping! Jumping! Jumping!
给你一长度为n的序列,求非连续的最大递增子序列的和,多组数据

思路:

image 26

AC Code:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
#define debug(a) cout<<#a<<"="<<a<<endl;
// #define TDS_ACM_LOCAL
typedef long long ll;
const double PI=acos(-1.0);
const double e=exp(1.0);
const int M=1e9+7;
const int N=1009;
inline int mymax(int x,int y){return x>y?x:y;}
inline int mymin(int x,int y){return x<y?x:y;}
inline int read(){
    register int x=0, f=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return f?-x:x;
}
inline void write(register int x){
    if(x < 0) {putchar('-');x = -x;}
    if(x > 9)  write(x/10);
    putchar(x % 10 + '0');
}
int n, a[N];
int dp[N];
void solve(){
    while(~scanf("%d", &n) && n){
        for(int i=1; i<=n; i++) a[i]=read(), dp[i]=a[i];
        int ans=-INF;
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++)
                if(a[j]>a[i])
                    dp[j]=mymax(dp[j], dp[i]+a[j]);
            ans=mymax(ans, dp[i]);
        }
        write(ans);
        putchar('\n');
    }
	return ;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
    freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
    freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
    solve();
    return 0;
}

平平无奇的在校大学生