Little Red Riding Hood

Time Limit: 1 Sec  Memory Limit: 1280 MB
Submit: 853  Solved: 129
[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 (

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. 1
  2. 3 1
  3. 2 1 3

Sample Output

  1. 5
    【分析】给你一个数组,然后让你从中选出一些数,使得和最大,但是当你选了一个数,距离这个数长度为 K 的数都会变为0,问
    你最终选的数的最大和。
    dp[i][0,1]表示不选当前数或选当前数的最大值。然后维护两个最大值max11~i-k 的最大值;max21~i的最大值,那么
    dp[i][1]=max1+a[i];
  1. #include <cstdio>
  2. #include <vector>
  3. #include <cstring>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <map>
  8. #include <cmath>
  9. #include <algorithm>
  10. using namespace std;
  11. typedef long long LL;
  12. typedef pair<int,int>pii;
  13. const int N = 1e5+;
  14. const double eps = 1e-;
  15. int T,n,w[N],sum[N<<],p[N<<],cnt,m,ret[N];
  16. int k,a[N],pos[N],vis[N],dp[N][];
  17. int main() {
  18. scanf("%d",&T);
  19. while(T--){
  20. scanf("%d%d",&n,&k);
  21. memset(dp,,sizeof dp);
  22. int ans=,max1=,max2=;
  23. for(int i=;i<=n;i++){
  24. scanf("%d",&a[i]);
  25. }
  26. for(int i=;i<=n;i++){
  27. dp[i][]=max2;
  28. dp[i][]=max1+a[i];
  29. if(i-k>=)max1=max(max1,max(dp[i-k][],dp[i-k][]));
  30. max2=max(dp[i][],dp[i][]);
  31. //printf("!!!%d %d\n",max1,max2);
  32. }
  33. printf("%d\n",max(dp[n][],dp[n][]));
  34. }
  35. return ;
  36. }
  1.  

HZAU 1199 Little Red Riding Hood(DP)的更多相关文章

  1. HZAU 1199: Little Red Riding Hood 01背包

    题目链接:1199: Little Red Riding Hood 思路:dp(i)表示前i朵花能取得的最大价值,每一朵花有两种选择,摘与不摘,摘了第i朵花后第i-k到i+k的花全部枯萎,那么摘的话d ...

  2. hzau 1199 Little Red Riding Hood

    1199: Little Red Riding Hood Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 918  Solved: 158[Submit ...

  3. Little Red Riding Hood

    问题 : Little Red Riding Hood 时间限制: 1 Sec  内存限制: 1280 MB 题目描述 Once upon a time, there was a little gir ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  6. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  7. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  8. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  9. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

随机推荐

  1. Android程序始终横屏

    在AndroidManifest.xml文件里面的activity标签中加入以下属性 android:screenOrientation="landscape" android:c ...

  2. 【bzoj3387-跨栏训练】线段树+dp

    我们可以想到一个dp方程:f[i][0]表示当前在i个栅栏的左端点,f[i][1]表示在右端点. 分两种情况: 第一种:假设现在要更新线段gh的左端点g,而它下来的路径被ef挡住了,那么必定是有ef来 ...

  3. 【BZOJ】1602:[Usaco2008 Oct]牧场行走

    [算法]最近公共祖先(LCA) [题解] 点x,y到最近公共祖先z的距离之和相当于x,y到根的距离减去两倍z到根的距离, 即ans=dis[x]+dis[y]-2*dis[z] 记得边数组要开两倍!! ...

  4. Apache的Commons Lang和BeanUtils

    1.字符串的空判断 //isEmpty System.out.println(StringUtils.isEmpty(null));      // true System.out.println(S ...

  5. LCD 每隔10分钟 自动熄灭 --打开Framebuffer console的时候【转】

    转自:http://blog.csdn.net/liujia2100/article/details/9009063 版权声明:本文为博主原创文章,未经博主允许不得转载. 之前移植LCD的时候,一切正 ...

  6. Laravel 调试器 Debugbar 和数据库导出利器 DbExporter 扩展安装及注意事项

    一.Debugbar安装 参考:Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程 的“2.安装”部分 二.DbExporter安装 参考:Laravel 扩展推荐 ...

  7. python并发模块之concurrent.futures(二)

    python并发模块之concurrent.futures(二) 上次我们简单的了解下,模块的一些基本方法和用法,这里我们进一步对concurrent.futures做一个了解和拓展.上次的内容点这. ...

  8. python windows下安装celery调度任务时出错

    由于celery 4.0不支持windows系统.所以用命令pip install Celery安装的celery是最新版4.0的不能在windows下运行. 在windows命令窗口运行: cele ...

  9. C基础 大文件读取通过标准库

    引言 - 问题的构建 C大部分读取文件的时候采用fgetc, 最近在使用过程中发现性能不是很理想.都懂得fgetc每次只能读取一个字符, IO操作太频繁. 所以性能低. 本文希望通过标准库函数frea ...

  10. C基础 多用户分级日志库 sclog

    引言 - sclog 总的设计思路 sclog在之前已经内置到simplec 简易c开发框架中一个日志库. 最近对其重新设计了一下. 减少了对外暴露的接口. 也是C开发中一个轮子. 比较简单, 非常适 ...