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 ...
随机推荐
- .net core Fundamentals
• Application Startup 應用程序啟動 • Middleware 中間件 • Working with Static Files 靜態文件 • Routing 路由 • URL Re ...
- centos7 多版本python并存问题
新的阿里云服务器,本身装有python2.7,但是项目需要python3,于是只能再装一个python3.6 参考文章:https://www.cnblogs.com/johnny1024/p/844 ...
- Eclipse连接海马模拟器
找到海马模拟器安装目录: 使用cmd 命令进入命令行:D: cd:D:\Program Files (x86)\Droid4X 进入模拟器所在目录 运行adb connect 127.0.0.1:26 ...
- ew做socks5代理
这个工具和之前讲过的xxoo类似.链接:https://www.cnblogs.com/nul1/p/8883271.html https://zhuanlan.zhihu.com/p/3282215 ...
- deepin安装metasploit
[1]安装metasploit 1.curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/tem ...
- ubuntu下定时弹窗记录工作日志
背景 记录工作日志,是一个很好的习惯,但不容易坚持,本来打算每天记录,但经常拖延,拖着拖着,有一些事情就忘记了. 等到写周报或月报的时候,才会开始翻邮件,聊天记录,各个仓库的提交log等,回忆都干了些 ...
- python实战===百度文字识别sdk
http://ai.baidu.com/docs#/OCR-Python-SDK/top
- caffe Python API 之LRN
net.mylrn = caffe.layers.LRN(net.pool1,local_size=5,alpha=1e-4,beta=0.75) 输出: layer { name: "my ...
- echarts3.0版本断点连线的处理
项目应用到echarts图表组件.官网的demo中出现空数据会断开.经过跟踪调试.修改echarts.js以下代码即可实现断点连线功能(需要将空数据处理成'-'.这样才能均值): for (var ...
- LeetCode解题报告—— Jump Game & Merge Intervals & Permutation Sequence
1. Jump Game Given an array of non-negative integers, you are initially positioned at the first inde ...