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 ...
随机推荐
- Python 19 Django 详解
本节概要 Django详解 前言 有一部分原因是,确实djando的课程有点多:并且,最近又在研究利用python做数据分析时间上耽误了.所以楼主讲所有的课程全部重新观看了一遍,再来撰写博客,其实说起 ...
- 【tmos】创建自定义400、500页面
解决方案
- 使用WebView时软键盘遮挡H5页面解决办法
简单解决办法:在清单文件中添加 android:windowSoftInputMode="adjustResize" 此举可在软键盘弹出时,重新测量布局,保证不遮挡光标的所在位置. ...
- jQuery单选框的回显
代码示例: html: <div class="col-lg-4"> <label class="radio-inline"> < ...
- ethtool 解决网卡丢包严重和网卡原理【转】
转自:https://blog.csdn.net/u011857683/article/details/83758869 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- ARMCC和GCC编译ARM代码的软浮点和硬浮点问题 【转】
转自:http://houh-1984.blog.163.com/blog/static/31127834201211112129167/ 本文介绍了ARM代码编译时的软浮点(soft-float)和 ...
- POJ3580 SuperMemo splay伸展树,区间操作
题意:实现一种数据结构,支持对一个数列的 6 种操作:第 x 个数到第 y 个数之间的数每个加 D:第 x 个数到第 y 个数之间全部数翻转:第 x 个数到第 y 个数之间的数,向后循环流动 c 次, ...
- 删除元素splice、shift\pop
splice() 方法: 向/从数组中添加/删除项目,然后返回被删除的项目. splice( index位数, 数量, 新添加 ) 该方法会改变原始数组 删除数组中第一个元素 arr.shift( ...
- python 基础 Two day
1.格式化输出 %s 字符串 %d 数字 %% 转义 % %f 小数 现在有以下需求,让用户输入name, age, job,hobby 然后输出如下所示: ------------ i ...
- 【原创】大叔经验分享(40)hdfs关闭kerberos
hadoop.security.authentication: Kerberos -> Simple hadoop.security.authorization: true -> fals ...