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 的异步 IO:Asyncio 简介
转载自https://segmentfault.com/a/1190000008814676 好文章 所谓「异步 IO」,就是你发起一个 IO 操作,却不用等它结束,你可以继续做其他事情,当它结束时, ...
- mysql 原理~ FTWRDL
FTWRL 锁与MDL一 简介:今天来聊聊为什么备份会卡住,申请不到全局FTWRL二 FTWRL 1 FTWRL主要包括3个步骤: 1.上全局读锁(lock_global_read_lo ...
- Ajax 及里面的XStream《黑马程序员_超全面的JavaWeb视频教程vedio》
1. ajax是什么? * asynchronous javascript and xml:异步的js和xml * 它能使用js访问服务器,而且是异步访问! * 服务器给客户端的响应一般是整个页面,一 ...
- Git更新远程仓库代码到本地(转)
参考链接:https://blog.csdn.net/chailyuan/article/details/53292031 在下载一个较大的github项目以后,当该项目代码更新以后,我们想将更新的内 ...
- stega -- Pcat老入群题
stega -- Pcat老入群题 Pcat师傅的题果然给力,就是看着wp也是琢磨了半天. WP地址:http://mp.weixin.qq.com/s/T9jJLACiZNB6FR226IjmEA ...
- python - pymysql模块
pymsql 模块 基本应用介绍: # 安装模块 pip install PyMySql # 导入模块 import pymysql # 配置连接信息 config = { 'host':'127.0 ...
- wx小程序-起航!
手动创建 入口配置文件 app 页面文件新创建一个文件夹 然后在里面分类 1.文件夹名可以不一样,但是里面的wxml,wxss,json 等文件名必须保持一致 2.app.json 入口文件, ...
- Microsoft SQL - 操作语句
操作语句(Operation Statement) 操作数据库 创建数据库 关键字:create database 用于创建各种数据库对象(数据库.表.触发器.存储过程等) 格式如:create &l ...
- 20165234 《Java程序设计》第五周学习总结
第五周学习总结 教材学习内容总结 第七章 内部类与异常类 内部类 内部类:在一个类中定义另一个类. 外嵌类:包含内部类的类,称为内部类的外嵌类. 内部类的类体中不能声明类变量和类方法.外嵌类的类体中可 ...
- 【NLP CS224N笔记】Lecture 1 - Introduction of NLP
I. 什么是NLP NLP全称是Natural Language Processing,即自然语言处理,这是一门计算机科学.人工智能以及语言学的交叉学科. NLP涉及的几个层次由下图所示.可以看到输入 ...