HZAU 网络赛 Little Red Riding Hood
来源:互联网 发布:怎么在美拍加淘宝链接 编辑:程序博客网 时间:2024/06/03 08:52
1199: Little Red Riding Hood
Submit: 898 Solved: 149
[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
简单题,写出状态转移方程即可(与Estrella's Travel类似)
设f[i]表示从前(i+1)个数中选出相距大于k的最大和
当i=0时, f[i]=a[i];
当0<i<=k时,f[i]=max(f[i-1],a[i]);
当i>k时,f[i]=max(f[i-1],f[i-k-1]+a[i]);
#include <bits/stdc++.h>using namespace std;#define mst(a,b) memset((a),(b),sizeof(a))#define f(i,a,b) for(ll i=(a);i<(b);++i)const int maxn = 100005;const long long mod = 1000000007;#define ll long long#define rush() int T;scanf("%d",&T);while(T--)int ans[maxn];int main(){ int n,k,x; rush() { mst(ans,0); scanf("%d%d",&n,&k); for(int i=0;i<n;i++) { scanf("%d",&x); if(i==0) ans[i]=x; else if(i>0&&i<=k) ans[i]=max(ans[i-1],x); else ans[i]=max(ans[i-1],ans[i-k-1]+x); } printf("%d\n",ans[n-1]); } return 0;}
- HZAU 网络赛 Little Red Riding Hood
- 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)
- 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 背包)
- HZAU 网络赛 Sequence Number
- hzau华中农业大学第四届程序设计大赛网络同步赛F.LCS
- 有一种绝望叫做无限PE hzau 1207 Candies (华中农业大学第五届程序设计大赛网络同步赛 I题)
- red hat网络配置
- 2014广州网络赛 Wang Xifeng's Little Plot
- 01字典树小结-2017HZAU现场赛H-MathematicalGame
- 有关二叉树的计算
- 26. Remove Duplicates from Sorted Array
- ASP .NET MVC ORM 数据库优先
- 报头压缩-ROHC基本概念
- Oracle操作用户和表空间的总结
- HZAU 网络赛 Little Red Riding Hood
- XUtils
- scala版本kafka createStream
- Scala 学习(四)--- 集合
- oracle数据库中的集合运算 ,索引,视图,伪劣
- SpringMVC中一个Handler(处理器)配置专属的拦截器组
- JS数组
- Linux系统中切换用户身份su与sudo的用法与实例
- Git从本地添加项目到远程仓库