HZAU 1199 Little Red Riding Hood
来源:互联网 发布:java if 缩写 编辑:程序博客网 时间:2024/06/03 19:26
1199: Little Red Riding Hood
Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 892 Solved: 144
[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 (2 <= n <= 10^5 ) ,1 <= k <= n ), the second line of them input n positive integers a (1<=a <=10^5)
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
官方题解:
Source
示例程序#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int t,n,k,i,dp[100001],a[100001]; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&k); memset(dp,0,sizeof(dp)); for(i=1;n>=i;i++) { scanf("%d",&a[i]); } dp[1]=a[1]; for(i=2;k+1>=i;i++) { dp[i]=max(a[i],dp[i-1]); } for(i=k+2;n>=i;i++) { dp[i]=max(dp[i-1],dp[i-k-1]+a[i]); } printf("%d\n",dp[n]); } return 0;} /************************************************************** Problem: 1199 Code Length: 668 B Language: C++ Result: Accepted Time:252 ms Memory:1744 kb****************************************************************/
- HZAU 1199 Little Red Riding Hood
- HZAU 1199 Little Red Riding Hood (dp)
- HZAU 1199: Little Red Riding Hood 01背包
- HZAU 1199 Little Red Riding Hood(水DP)
- HZAU 网络赛 Little Red Riding Hood
- Little Red Riding Hood
- HAU校赛Little Red Riding Hood
- hazu A. Little Red Riding Hood (DP)@
- Problem A: Little Red Riding Hood----普通dp
- 华中农业大学第五届程序设计大赛 A Little Red Riding Hood [BIT优化dp]【动态规划】
- 湖北民族学院oj 1877 之 Little Red Riding Hood(dp)
- HZAU_1199_Little Red Riding Hood(DP 背包)
- Red
- red
- HZAU 1000 Enrolling
- HZAU 1005 Balance
- HZAU 1003 Alien invasion
- HZAU 1018 Catching Dogs
- 第四届省赛原题 序号互换
- Hibernate 级联操作,映射文件中的默认的Lazy属性导致的异常
- PreparedStatement与Statement
- Oracle查询表空间使用情况
- xshell常用命令
- HZAU 1199 Little Red Riding Hood
- IntelliJ IDEA 2017.1注册码失效问题解决方案
- 深度学习之生成对抗网络GAN
- C-UDP-广播模型
- Java---(SpringBlade框架)后台从数据库读取所有点的经度和纬度,传输到前端显示在地图上
- [LeetCode]563. Binary Tree Tilt
- Zookeeper集群的搭建
- 封装$(id)函数
- Java表达式的陷阱——多线程的陷阱