zoukankan      html  css  js  c++  java
  • 华中农业大学第五届程序设计大赛网络同步赛-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 }
  • 相关阅读:
    CSP-S2019游记
    BZOJ4668 冷战
    [ZJOI2007]仓库建设
    CF833B The Bakery
    决策单调性优化DP+分治优化决策单调性
    穿越栅栏 Overfencing
    控制公司 Controlling Companies
    派对灯 Party Lamps
    CSP2019总结
    差分约束
  • 原文地址:https://www.cnblogs.com/Penn000/p/6756220.html
Copyright © 2011-2022 走看看