题解 | #选人#

选人

https://ac.nowcoder.com/acm/problem/210734

水题

#include <bits/stdc++.h>

#define ll long long
#define int long long
#define pii pair<int, int>
using namespace std;
const int maxn = 1e5+10;
const ll inf = 1e18;

template <typename _tp>
inline void read(_tp& x) {
    char ch = getchar(), sgn = 0;
    while (ch ^ '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') ch = getchar(), sgn = 1;
    for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    if (sgn) x = -x;
}
int f[maxn][110][2];
int n, m, a[maxn];
signed main(){
    read(n), read(m);
    for(int i = 1; i <= n; ++i) read(a[i]);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= min(i, m); ++j){
            f[i][j][1] = max(f[i-1][j][1] + a[i], f[i-1][j-1][0] + a[i]);
            f[i][j][0] = max(f[i-1][j][0], f[i-1][j][1]);
        }
    }
    printf("%lld", max(f[n][m][1], f[n][m][0]));
    //return 0;
}
全部评论
我的不知道为什么莫名超时了
点赞 回复 分享
发布于 2024-05-14 17:17 美国

相关推荐

12-15 18:00
巨人网络_招聘
投递巨人网络等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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