Little Red Riding Hood

<center style="color&#58;rgba&#40;0&#44;0&#44;0&#44;&#46;87&#41;&#59;font&#45;family&#58;Lato&#44; &#39;Helvetica Neue&#39;&#44; Arial&#44; Helvetica&#44; sans&#45;serif&#59;">

问题 : Little Red Riding Hood

时间限制: 1 Sec  内存限制: 1280 MB
</center>

题目描述

    Once upon a time, there was a little girl. Her name was Little Red Riding Hood. One day, her grandma was ill. Little Red Riding Hood went to visit her. On the way, she met a big wolf. “That's a good idea.”,the big wolf thought. And he said to the Little Red Riding Hood, “Little Red Riding Hood, the flowers are so beautiful. Why not pick some to your grandma?” “Why didn't I think of that? Thank you.” Little Red Riding Hood said.

    Then Little Red Riding Hood went to the grove to pick flowers. There were n flowers, each flower had a beauty degree a[i]. These flowers arrayed one by one in a row. The magic was that after Little Red Riding Hood pick a flower, the flowers which were exactly or less than d distances to it are quickly wither and fall, in other words, the beauty degrees of those flowers changed to zero. Little Red Riding Hood was very smart, and soon she took the most beautiful flowers to her grandma’s house, although she didn’t know the big wolf was waiting for her. Do you know the sum of beauty degrees of those flowers which Little Red Riding Hood pick? 

输入

    The first line input a positive integer T (1≤T≤100), indicates the number of test cases. Next, each test case occupies two lines. The first line of them input two positive integer n and

k (2 <= n <= 10^5 ) ,1 <=  k <= n ), the second line of them input n positive integers a (1<=a <=10^5)

输出

    Each group of outputs occupies one line and there are one number indicates the sum of the largest beauty degrees of flowers Little Red Riding Hood can pick. 

样例输入

1 
3 1 
2 1 3

样例输出

5
#include <stdio.h>
#define max(a, b) a > b ? a : b
int a[100010], dp[100010];
int main()
{
    int t, n, k, s;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        dp[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            if(i - k - 1 > 0)
                s = dp[i - k - 1];
            else s = 0;
            dp[i] = max(dp[i - 1], s + a[i]);
        }
        printf("%d\n", dp[n]);
    }
    return 0;
}
全部评论

相关推荐

勇敢的突尼斯海怪选钝...:楼主这拒意向话术好得体呀 !求问HR回复态度咋样呀
点赞 评论 收藏
分享
dachang盒子:26届秋招必须有实习经历,建议找个实习过度下,同时项目重复率也比较高没有什么难点亮点,我这里有大厂真实的项目可以提供给你学习也可以给你包装大厂实习来提高你的竞争力,感兴趣的话可以私信我或者点我主页简介
你已经投递多少份简历了
点赞 评论 收藏
分享
12-26 14:44
复旦大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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