• 华中农业大学第五届程序设计大赛网络同步赛-A


    Problem A: Little Red Riding Hood

    Time Limit: 1 Sec  Memory Limit: 1280 MB
    Submit: 860  Solved: 133
    [Submit][Status][Web Board]

     

    Description

    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? 

    Input

    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 (

    Output

     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. 

    Sample Input

    1 
    3 1 
    2 1 3
    

    Sample Output

    5
    

    HINT

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 int a[100005], dp[100005];
     9 
    10 int main()
    11 {
    12     int T, n, k;
    13     scanf("%d", &T);
    14     while(T--)
    15     {
    16         scanf("%d%d", &n, &k);
    17         for(int i = 0; i < n; i++){
    18             scanf("%d", &a[i]);
    19             dp[i] = a[i];
    20         }
    21         int mx = dp[0];
    22         int ans = 0;
    23         for(int i = k+1; i < n; i++)
    24         {
    25             mx = max(mx, dp[i-k-1]);
    26             dp[i] = a[i] + mx;
    27             if(ans < dp[i])ans = dp[i];
    28         }
    29         printf("%d
    ", ans);
    30     }
    31 
    32     return 0;
    33 }
  • 相关阅读:
    第 17 章 责任链模式【Chain of Responsibility Pattern】
    第 16 章 观察者模式【Observer Pattern】
    第 15 章 组合模式【Composite Pattern】
    第 14 章 迭代器模式【Iterator Pattern】
    第 13 章 装饰模式【Decorator Pattern】
    第 12 章 命令模式【Command Pattern】
    第 11 章 桥梁模式【Bridge Pattern】
    第 10 章 建造者模式【Builder Pattern】
    编写高质量代码改善C#程序的157个建议——导航开篇
    C#实现简易ajax调用后台方法
  • 原文地址:https://www.cnblogs.com/Penn000/p/6756220.html
Copyright © 2020-2023  润新知