每日一题 3月27日 数学考试 线性DP

数学考试

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

图片说明

思路:很容易可以看出来是一个线性DP。
图片说明

#include <bits/stdc++.h>
using namespace std;
#define LL long long

LL a[200005], f[200005];
int main(){

    int t; scanf("%d", &t);
    while(t--){
        int n, k; scanf("%d%d", &n, &k);
        for(int i=1; i<=n; i++){
            scanf("%lld", &a[i]);
            a[i]+=a[i-1];
            f[i]=-1ll<<60;
        }
        LL mx=-1ll<<60;
        for(int i=k; i<=n; i++){
            f[i]=max(f[i-1], (a[i]-a[i-k]));
            if(i>=2*k){
                mx=max(mx, (a[i]-a[i-k])+f[i-k]);
            }
        }
        printf("%lld\n", mx);
    }

    return 0;
}
全部评论

相关推荐

“校招”、“3-5年经验”
xiaolihuam...:逆向工程不是搞外挂的吗,好像现在大学生坐牢最多的就是诈骗罪和非法侵入计算机系统罪,发美金,还居家办公,就是怕被一锅端,
点赞 评论 收藏
分享
我:“加班需要有加班工资。”&nbsp;hr:“为什么?”&nbsp;哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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