Little Red Riding Hood
问题 : Little Red Riding Hood
时间限制: 1 Sec 内存限制: 1280 MB
题目描述
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; }
Little Red Riding Hood的更多相关文章
- HZAU 1199: Little Red Riding Hood 01背包
题目链接:1199: Little Red Riding Hood 思路:dp(i)表示前i朵花能取得的最大价值,每一朵花有两种选择,摘与不摘,摘了第i朵花后第i-k到i+k的花全部枯萎,那么摘的话d ...
- HZAU 1199 Little Red Riding Hood(DP)
Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 853 Solved: 129[Submit][Stat ...
- hzau 1199 Little Red Riding Hood
1199: Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 918 Solved: 158[Submit ...
- 10 分钟学会Linux常用 bash命令
目录 基本操作 1.1. 文件操作 1.2. 文本操作 1.3. 目录操作 1.4. SSH, 系统信息 & 网络操作 基本 Shell 编程 2.1. 变量 2.2. 字符串替换 2.3. ...
- TensorFlow从1到2(五)图片内容识别和自然语言语义识别
Keras内置的预定义模型 上一节我们讲过了完整的保存模型及其训练完成的参数. Keras中使用这种方式,预置了多个著名的成熟神经网络模型.当然,这实际是Keras的功劳,并不适合算在TensorFl ...
- bash guide
Table of Contents Basic Operations 1.1. File Operations 1.2. Text Operations 1.3. Directory Operatio ...
- 华中农业大学第五届程序设计大赛网络同步赛-A
Problem A: Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 860 Solved: 133[S ...
- Django Model 数据表
Django Model 定义语法 版本:1.7主要来源:https://docs.djangoproject.com/en/1.7/topics/db/models/ 简单用法 from djang ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
随机推荐
- ES学习
官方参考手册 https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html https://www.elastic.co ...
- s9.16作业,员工信息表
转载https://blog.csdn.net/qq_35883464/article/details/83151464 实现员工信息表文件存储格式如下:id,name,age,phone,job1, ...
- centos 6.8下载地址
centos6.8校验码查询网站:https://wiki.centos.org/zh-tw/Manuals/ReleaseNotes/CentOS6.8 CentOS 6.8 64位DVD 种子下载 ...
- maven(一) 一 修改仓库存放路径
一.修改仓库存放路径 maven默认的仓库是在C盘下的,这样当重新装系统的时候,仓库就要重新建了.因此可以修改默认存放的位置. 修改仓库的地址在maven安装包(即apache-maven-bin)下 ...
- jQuery单选框的回显
代码示例: html: <div class="col-lg-4"> <label class="radio-inline"> < ...
- 搭建ubuntu14.04服务器必备环境
1. 设置网络 设置网络时,一定要设置好网卡,第一个网卡一定要设置为‘br0’(如下图),设置为其他的上不去网. 修改网络配置文件,命令:sudo gedit /etc/network/interf ...
- Linux Shell脚本编程
⒈为什么要学习Shell编程 1)Linux运维工程师在进行服务器集群管理时,需要编写Shell程序来进行服务器管理 2)对于JavaEE和Python程序员来说,有些工作需要编写一些Shell脚本进 ...
- 【转】Python标准模块--importlib
[转]Python标准模块--importlib 作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 1 模块简介 P ...
- 【转】Python之系统交互(subprocess)
[转]Python之系统交互(subprocess) 本节内容 os与commands模块 subprocess模块 subprocess.Popen类 总结 我们几乎可以在任何操作系统上通过命令行指 ...
- Threading.local
在多线程环境下,每个线程都有自己的数据.一个线程使用自己的局部变量比使用全局变量好,因为局部变量只有线程自己能看见,不会影响其他线程,而全局变量的修改必须加锁. Threading.local可以创建 ...