Little Red Riding Hood
来源:互联网 发布:53端口 转发 编辑:程序博客网 时间:2024/06/14 08:39
题目描述
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"iostream"#include"string.h"using namespace std;int ai[100100];int dp[100100];int main(){ int t,n,k; cin>>t; while(t--) { cin>>n>>k; for(int i=1;i<=n;i++) { cin>>ai[i]; } for(int i=1;i<=n;i++) { dp[i]=dp[i-1]; if(i<=k+1) dp[i]=max(dp[i],ai[i]); else dp[i]=max(dp[i],dp[i-k-1]+ai[i]); } cout<<dp[n]<<endl; } return 0;}
- Little Red Riding Hood
- HAU校赛Little Red Riding Hood
- hazu A. Little Red Riding Hood (DP)@
- HZAU 1199 Little Red Riding Hood
- HZAU 网络赛 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)
- 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
- when riding to dom
- Riding Down from Bangor
- usaco Riding the Fences
- Riding the Fences
- 简单计算器
- 【JavaEE】Java跨平台原理
- 利用分页插件对Ajax请求到后台数据进行分页
- 使用SOCKET实现TCP/IP协议的通讯
- 跨域请求之CORS
- Little Red Riding Hood
- synchronize的使用
- X Samara Regional Intercollegiate Programming Contest
- css定位之position详细解读
- 儿子回去了
- Google关于BigTable技术论文中文版
- 简述java中两种实现多态的方法
- JAVA 基本类型的默认值和取值范围
- hihoCoder 1041 : 国庆出游 (dfs+bitset 很不错的题!)