5、最大花之能量

题目 最大花之能量

image-e09c9cda

思路分析

线性dp最长上升子序列的板子题

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

const int N=1e3+10;

int w[N],f[N];

int main()

{

    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;cin>>n;

    for(int i=1;i<=n;i++){

        cin>>w[i];

        f[i]=w[i];

    }

    for(int i=1;i<=n;i++){

        for(int k=1;k<i;k++){

            if(w[k]<w[i]){

                f[i]=max(f[i],f[k]+w[i]);

            }

        }

    }

    int res=0;

    for(int i=1;i<=n;i++){

        res=max(res,f[i]);

    }

    cout<<res;

    return 0;

}

同类题型

视频讲解


⬅️ 4、对称排序 🏠 00-刷题理模型 ➡️ 6、七彩之城的独特序列