题解 | #删除相邻数字的最大分数#

删除相邻数字的最大分数

https://www.nowcoder.com/practice/3bcf72c738b6494bbe1ebe0ffde56152

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int x[10001] = {0},y[10001] = {0};
    int arr[10001] = { 0 };
    for (int i = 0; i < n; i++) {
        int x = 0;
        cin >> x;
        arr[x] += x;
    }

    for(int j=1;j<10001;j++)
    {
        x[j] = arr[j] + y[j-1];
        y[j] = max(x[j-1],y[j-1]);
    }

    cout<<(x[10000]>y[10000] ? x[10000] : y[10000])<<endl;
    

    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
ResourceUt...:你是我见过最美的牛客女孩
晒一下我的毕业照
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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