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

Sample Output

5
【分析】给你一个数组,然后让你从中选出一些数,使得和最大,但是当你选了一个数,距离这个数长度为 K 的数都会变为0,问
你最终选的数的最大和。
dp[i][0,1]表示不选当前数或选当前数的最大值。然后维护两个最大值max1:1~i-k 的最大值;max2:1~i的最大值,那么
dp[i][1]=max1+a[i];
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N = 1e5+;
const double eps = 1e-;
int T,n,w[N],sum[N<<],p[N<<],cnt,m,ret[N];
int k,a[N],pos[N],vis[N],dp[N][];
int main() {
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&k);
memset(dp,,sizeof dp);
int ans=,max1=,max2=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++){
dp[i][]=max2;
dp[i][]=max1+a[i];
if(i-k>=)max1=max(max1,max(dp[i-k][],dp[i-k][]));
max2=max(dp[i][],dp[i][]);
//printf("!!!%d %d\n",max1,max2);
}
printf("%d\n",max(dp[n][],dp[n][]));
}
return ;
}
												

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. asp.net SimpleImpersonation使用身份模拟访问局域网共享目录

    mvc中默认账户的权限很低,缺省情况下,ASP.NET应用程序以本机的ASPNET帐号运行,该帐号属于普通用户组,权限受到一定的限制,以保障ASP.NET应用程序运行的安全.但是有时需要某个ASP.N ...

  2. PHP 数据加密

    <?php /** * * 加密 * */ function lock_url($txt, $key = "aiteng") { $chars = "ABCDEFG ...

  3. 【HDU】6012 Lotus and Horticulture (BC#91 T2)

    [算法]离散化 [题解] 答案一定存在于区间的左右端点.与区间左右端点距离0.5的点上 于是把所有坐标扩大一倍,排序(即离散化). 让某个点的前缀和表示该点的答案. 初始sum=∑c[i] 在l[i] ...

  4. winform Textbox像百度一下实现下拉显示

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. 首行缩进css

    html首行缩进2字符,可以使用CSS属性中的[text-indent]进行设置. 设置代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  6. 2.0 docker安装

    问题列表: Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again 解:处 ...

  7. 【转】关于Scapy

    关于Scapy Scapy的是一个强大的交互式数据包处理程序(使用python编写).它能够伪造 或者解码大量的网络协议数据包,能够发送.捕捉.匹配请求和回复包等等.它可以很容易地处理一些典型操作,比 ...

  8. HTTP响应码摘自apach官网

    HTTP状态列表 响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行. 响应码分五种类型,由它们的第一位数字表示: 1xx:信息,请求收到,继续处理 2xx:成功,行为被成功地接 ...

  9. HashMap 、LinkedHashMap、HashTable、TreeMap 和 Properties 的区别

    HashMap 1.线程不安全: 2.允许null value 和 null key: 3.访问效率比较高: 4.Java1.2引进的Map接口的一个实现: 5.轻量级: 6.根据键的HashCode ...

  10. python基础===python os.path模块

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...