HZAU 1199 Little Red Riding Hood(DP)
Little Red Riding Hood
Time Limit: 1 Sec Memory Limit: 1280 MB
Submit: 853 Solved: 129
[Submit][Status][Web Board]
Description
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.
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
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)的更多相关文章
- HZAU 1199: Little Red Riding Hood 01背包
题目链接:1199: Little Red Riding Hood 思路:dp(i)表示前i朵花能取得的最大价值,每一朵花有两种选择,摘与不摘,摘了第i朵花后第i-k到i+k的花全部枯萎,那么摘的话d ...
- hzau 1199 Little Red Riding Hood
1199: Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 918 Solved: 158[Submit ...
- Little Red Riding Hood
问题 : Little Red Riding Hood 时间限制: 1 Sec 内存限制: 1280 MB 题目描述 Once upon a time, there was a little gir ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
随机推荐
- 搜索:BFS
如果题目真的要考察宽度优先搜索,那么这类题目往往具有比较大的编码难度,换个说法,就是细枝末节特别多,状态特别复杂.. 剥茧抽丝,这里以一个比较“裸”的BFS作为例子,了解一下实现BFS的一些规范. 直 ...
- 【BZOJ1272】Gate Of Babylon [Lucas][组合数][逆元]
Gate Of Babylon Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description Input ...
- embed标签 阻止点击事件 让父元素处理点击事件
由于规定页面显示的PDF文件要有固定大小,使得页面风格统一 最开始发现了CSS样式pointer-events 写出如下代码,在360急速浏览器急速模式中访问可在点击PDF控件时可跳转页面 <a ...
- C# IEqualityComparer 使用方法 Linq Distinct使用方法
创建 IEqualityComparer的接口类必须实现Equals和GetHashCode方法 public class TipComparer : IEqualityComparer<Tip ...
- net_dev_init
Kernel: 4.12.6 网络设备初始化,主要包括初始化softnet_data,注册收发包软中断等: static int __init net_dev_init(void) { int i, ...
- ThinkPHP3.1.3 整合 UEditor百度编辑器 图片上传
第一步.前端模板实例化百度编辑器 <js file='__ROOT__/Data/UEditor/ueditor.config.js' /> <js file='__ROOT__/D ...
- 【设计模式】迭代器模式(Iterator )
摘要: 1.本文将详细介绍迭代器模式的原理和实际代码中特别是Android系统代码中的应用. 纲要: 1. 引入迭代器模式 2. 迭代器的概念及优缺点介绍 3. 迭代器在Android源码中的应用 1 ...
- windows7 能连接移动硬盘 无法显示盘符
右键点我的电脑,管理里,点磁盘管理,看盘认到没,有时候认到了但是没给盘符,需要自己手动给一个
- PhysX SDK src
PhysX SDK src Physx3.3 source code http://download.csdn.net/download/qq122252656/9427387 Nvidia CUDA ...
- DOM编程艺术读书笔记 (须熟读)
http://www.qdfuns.com/notes/39151/00d8bc6322359f00450f492ae56bf69e.html