题解 | #最大上升子序列和#C代码

最大上升子序列和

https://www.nowcoder.com/practice/dcb97b18715141599b64dbdb8cdea3bd

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int max(int a,int b)
{
    if(a>=b)return a;
    else 
    return b;
}
int main() {
    int n;
    int num[1001];
    int dp[1001];
    while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case
        for(int i=0;i<n;i++)
        scanf("%d",&num[i]);
        dp[0]=0;
        int max1=0;
        for(int i=0;i<n;i++)
        {
            dp[i]=num[i];
            for(int j=0;j<i;j++)
            {
                if(num[i]>num[j])dp[i]=max(dp[i],dp[j]+num[i]);
            }
            max1=max(max1,dp[i]);
        }
        printf("%d\n",max1);
    }
    return 0;
}

全部评论

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务