九度 oj 题目1480:最大上升子序列和

http://ac.jobdu.com/problem.php?pid=1480


#include 
#include 
#include 


int main(){ 
    //freopen("in/1480.in","r",stdin); 
    int dp[1005],a[1005],n; 
    while(scanf("%d",&n) !=EOF){ 
        for (int i = 1; i <=n; ++i){ 
             scanf("%d",&a[i]);
        }     
        for (int i = 1; i <=n; ++i) { 
            dp[i] = a[i]; 
        } 

        for (int i = 1; i <=n; ++i) { 
            for (int j = 1; j  a[j]){ 
                    dp[i] = std::max(dp[i],a[i] + dp[j]);
                }  
            }  
        } 

        int max_sum = dp[1];
        for (int i = 2; i <=n ; ++i) { 
            if (max_sum < dp[i]) { 
                max_sum = dp[i]; 
            }  
        } 
        printf("%d\n",max_sum); 
    }  
}  


你可能感兴趣的:(oj,九度,动态规划)