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 ...
随机推荐
- Android程序始终横屏
在AndroidManifest.xml文件里面的activity标签中加入以下属性 android:screenOrientation="landscape" android:c ...
- 【bzoj3387-跨栏训练】线段树+dp
我们可以想到一个dp方程:f[i][0]表示当前在i个栅栏的左端点,f[i][1]表示在右端点. 分两种情况: 第一种:假设现在要更新线段gh的左端点g,而它下来的路径被ef挡住了,那么必定是有ef来 ...
- 【BZOJ】1602:[Usaco2008 Oct]牧场行走
[算法]最近公共祖先(LCA) [题解] 点x,y到最近公共祖先z的距离之和相当于x,y到根的距离减去两倍z到根的距离, 即ans=dis[x]+dis[y]-2*dis[z] 记得边数组要开两倍!! ...
- Apache的Commons Lang和BeanUtils
1.字符串的空判断 //isEmpty System.out.println(StringUtils.isEmpty(null)); // true System.out.println(S ...
- LCD 每隔10分钟 自动熄灭 --打开Framebuffer console的时候【转】
转自:http://blog.csdn.net/liujia2100/article/details/9009063 版权声明:本文为博主原创文章,未经博主允许不得转载. 之前移植LCD的时候,一切正 ...
- Laravel 调试器 Debugbar 和数据库导出利器 DbExporter 扩展安装及注意事项
一.Debugbar安装 参考:Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程 的“2.安装”部分 二.DbExporter安装 参考:Laravel 扩展推荐 ...
- python并发模块之concurrent.futures(二)
python并发模块之concurrent.futures(二) 上次我们简单的了解下,模块的一些基本方法和用法,这里我们进一步对concurrent.futures做一个了解和拓展.上次的内容点这. ...
- python windows下安装celery调度任务时出错
由于celery 4.0不支持windows系统.所以用命令pip install Celery安装的celery是最新版4.0的不能在windows下运行. 在windows命令窗口运行: cele ...
- C基础 大文件读取通过标准库
引言 - 问题的构建 C大部分读取文件的时候采用fgetc, 最近在使用过程中发现性能不是很理想.都懂得fgetc每次只能读取一个字符, IO操作太频繁. 所以性能低. 本文希望通过标准库函数frea ...
- C基础 多用户分级日志库 sclog
引言 - sclog 总的设计思路 sclog在之前已经内置到simplec 简易c开发框架中一个日志库. 最近对其重新设计了一下. 减少了对外暴露的接口. 也是C开发中一个轮子. 比较简单, 非常适 ...