#include <stdio.h>

int num[1001];
int dp[1001];

int max(int a,int b) {
    return a>b? a:b;
}
int bottom_up(int n) {
    int res=0;
    for(int i=1; i<=n; i++) {
        //기저
        dp[i]=num[i];
        
        for(int j=1; j<=i-1; j++) {
            ///i>j 수가 증가할때  합이 가장 클때
            if(num[i]>num[j]) dp[i]=max(dp[i],dp[j]+num[i]);
        }
        res=max(res,dp[i]);
    }
    return res;
}

int main() {
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%d",&num[i]);
    }
    printf("%d",bottom_up(n));
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: