题目:

Little Red Riding Hood

题目描述

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

题目描述:

动态规划题,设dp[i]为到拿取第i个位置的最大价值,推出转移方程即可。

代码:

#include<stdio.h>
#include<string.h>
int a,b,aa[100010],c[100010],d[100010],f[100010];
int main()
{int i,j,k;int t;scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);memset(aa,0,sizeof(aa));memset(c,0,sizeof(c));memset(d,0,sizeof(d));memset(f,0,sizeof(f));int max = 0,max1 = 0;for(i = 1; i <= a;i ++){scanf("%d",&aa[i]);if(i -b-1 >= 1){if(max < aa[i -b-1]){max = aa[i -b-1];}}c[i] = max;if(i - b >= 1){if(max1 < aa[i - 1]){max1 = aa[i - 1];}}d[i] = max1;
//          printf("%d %d\n",c[i],d[i]);}f[1] = aa[1];int ma=0,ma1=0;for(i = 1;i <=a;i++){if(i-b-1>=1)if(ma<f[i-b-1])ma = f[i-b-1];
//          ma1 = 0;
//          if(i-b>=1){
//              for(j=i;j<i+b;j++)
//                  if(ma1<f[j])
//                      ma1 = f[j];
//          }f[i] = ma+aa[i]>f[i-1]?ma+aa[i]:f[i-1];
//          printf("!%d\n",f[i]);}printf("%d\n",f[a]);}return 0;
}

Little Red Riding Hood(动态规划)相关推荐

  1. Little Red Riding Hood

    问题 : Little Red Riding Hood 时间限制: 1 Sec  内存限制: 1280 MB 题目描述 Once upon a time, there was a little gir ...

  2. django 1.8 官方文档翻译:2-1-1 模型语法

    模型 模型是你的数据的唯一的.权威的信息源.它包含你所储存数据的必要字段和行为.通常,每个模型对应数据库中唯一的一张表. 基础: 每个模型都是django.db.models.Model 的一个Pyt ...

  3. gv推了sweethearts_3HAC0373-1

    3HAC0373-1 3HAC0373-1 3HAC0373-1 ------------------------------------------------------------------- ...

  4. 华中农业大学第五届程序设计大赛网络同步赛解题报告2(转)

    今天实在累了,还有的题晚点补.... 题目链接:http://acm.hzau.edu.cn/problemset.php?page=3 题目:acm.hzau.edu.cn/5th.pdf A:Li ...

  5. 华中农业大学第五届程序设计大赛 (7/12)

    今天实在累了,还有的题晚点补.... 题目链接:http://acm.hzau.edu.cn/problemset.php?page=3 题目:acm.hzau.edu.cn/5th.pdf A:Li ...

  6. Crack:GrapeCity Documents for Excel 6.0.1

    v6 中 GrapeCity Documents for Excel 的新增功能 ocuments for Excel (GcExcel) v6 版本现已上线!该版本引入了新的基于 JavaScrip ...

  7. 关于计算机的英语小品,英文好玩简短的小品

    1.搞笑简短的英语小品 The little girl liked wearing a red coat. So everybody called her Little Red Coat.One da ...

  8. 学计算机的学生用什么笔记本电脑,什么样的笔记本电脑对学生有好处?这再合适不过了!...

    课程,家庭作业和信息搜索...这些需求逐渐使笔记本电脑成为大学生的必需品. 笔记本电脑不仅是帮助学生完成家庭作业的学习工具,还可以用于学习后看电影并查找资源,以丰富学生的业余时间. 因此,对于大学生来 ...

  9. Django Model 定义语法

    版本:1.7 主要来源:https://docs.djangoproject.com/en/1.7/topics/db/models/ 简单用法 from django.db import model ...

最新文章

  1. oracle19c数据库清理,Oracle 19c集群重装
  2. 禁止程序接收鼠标事件的工具_VNC Viewer for Mac(远程桌面工具)免费版
  3. xshell 打开文件跳转到最后_xshell的快捷键(非常实用)
  4. PHP的CI框架流程基本熟悉
  5. C语言设备管理器作业,你知道到吗,C语言竟是如何调用硬件的?
  6. IE通过推理IE陈述的版本号
  7. 为什么[]==0;JavaScript里什么情况下a==!a为true呢?
  8. ACM PKU 2663 Tri Tiling http://acm.pku.edu.cn/JudgeOnline/problem?id=2663
  9. EntityFramework进阶——Entity Splitting和Table Splitting
  10. Oracle Merge Into 的用法详解实例
  11. 产品定额的一些陷阱思考
  12. HDOJ1018 ( Big Number ) 【斯特林公式---处理阶乘及阶乘位数的问题】
  13. 网络管理员掌握的学习方法
  14. 2022年使用的最佳Javascript库
  15. ubuntu 20 解决软件商店不可用问题
  16. 首信易支付 php,ZenCart首信易支付模块递交失败解决
  17. 服务器更换固态后如何安装系统,更换固态硬盘后安装操作系统的两种常用方法...
  18. 阿卡迪亚大学计算机专业好考吗,考上阿卡迪亚大学有多难?
  19. 手机通过蓝牙共享网络给电脑上网
  20. matlab中根据表格数据画图,excel 表格数据画图-如何利用matlab根据excel表格里面的数据画图...

热门文章

  1. 数据增强系列(2)如何使用Augly库进行数据增强
  2. 一台电脑同时上内网和外网
  3. 【渝粤题库】陕西师范大学201961 中外教育管理史 作业(专升本)
  4. 几分钟教你轻松搞定ALM安装
  5. 物联网+阿里云+小程序开发的一些工具和方法总结
  6. 【老生谈算法】matlab算法离合器——离合器
  7. Nodejs运行错误小结
  8. 搭建confluence服务器(详细操作+踩坑说明)
  9. 计算机毕业设计JAVA派大星水产商城mp4mybatis+源码+调试部署+系统+数据库+lw
  10. 超融合解决方案已成新黑马 市场排名初见端倪