hdu 2128 Frog(简单DP)
Frog
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 712 Accepted Submission(s): 338
original coordinate of Fog is 0. Fog can stay still or jump forward T units, A <= T <= B. Fog will eat up all the insects wherever he stays, but he will
get tired after K jumps and can not jump any more. The number of insects (always less than 10000) in each position of the path is given.
How many insects can Fog eat at most?
Note that Fog can only jump within the range [0, N), and whenever he jumps, his coordinate increases.
The first line contains an integer T indicating the number of test cases.
For each test case:
The first line contains four integers N, A, B(1 <= A <= B <= N), K (K >= 1).
The next line contains N integers, describing the number of insects in each position of the path.
Output one line containing an integer - the maximal number of insects that Fog can eat.
1
4 1 2 2
1 2 3 4
8
pid=2191" target="_blank">2191
pid=2175" target="_blank">2175
pid=2177" target="_blank">2177
2180题意:
长度为N的路上每单位长度上有一定数目的虫子val[i]。如今有一仅仅青蛙開始在位置0处(位置从0到N-1)。
它每次能跳的距离在[A,B]范围且它要么往前跳要么不跳。
且它最多能跳k次。青蛙每到一个地方都会把那个地方的虫子吃掉。如今告诉你每一个地方虫子的个数问你它最多能吃掉多少虫子。
思路:
dp[i][j]表示青蛙到第i个位置时跳了j步所吃的虫子最大数目。
那么dp[i][j]=max(dp[i-k][j-1])+val[i]。A<=k<=B.
让后递推即可了。
具体见代码:
#include <iostream>
#include<stdio.h>
using namespace std;
const int INF=0x3f3f3f3f;
int dp[150][150],val[150];
int main()
{
int n,k,a,b,lim,i,j,l,t,ans; scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&n,&a,&b,&k);
for(i=0;i<n;i++)
scanf("%d",&val[i]);
ans=dp[0][0]=val[0];
for(i=1;i<n;i++)
{
lim=min(i,k);
for(j=1;j<=lim;j++)
{
dp[i][j]=-INF;
for(l=a;i-l>=0&&l<=b;l++)//注意范围
dp[i][j]=max(dp[i][j],dp[i-l][j-1]+val[i]);
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
hdu 2128 Frog(简单DP)的更多相关文章
- hdu 4576 (简单dp+滚动数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...
- hdu 5037 Frog 贪心 dp
哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...
- HDU 2836 Traversal 简单DP + 树状数组
题意:给你一个序列,问相邻两数高度差绝对值小于等于H的子序列有多少个. dp[i]表示以i为结尾的子序列有多少,易知状态转移方程为:dp[i] = sum( dp[j] ) + 1;( abs( he ...
- hdu 5569 matrix(简单dp)
Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- HDU 5375 Gray code (简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Oth ...
- hdu 2084 数塔(简单dp)
题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
随机推荐
- [RxJS] Conclusion: when to use Subjects
As a conclusion to this course about RxJS subjects, let's review when and why should you use them. F ...
- Android自定义组件系列【5】——进阶实践(1)
接下来几篇文章将对任老师的博文<可下拉的PinnedHeaderExpandableListView的实现>分步骤来详细实现,来学习一下大神的代码并记录一下. 原文出处:http://bl ...
- INotifyPropertyChanged接口的详细说明
在windows phone开发8.1:数据绑定中,我们了解了数据绑定的基本知识.今后几篇文章会继续深入了解数据绑定.今天我们来看在数据绑定中十分重要的INotifyPropertyChanged接口 ...
- ios开发之手势处理 之手势识别一
#import "ViewController.h" @interface ViewController ()<UIGestureRecognizerDelegate> ...
- 开发文档生成工具----强大的Doxygen工具使用手册
张三:假如我们自己开发了一个类库,怎么做一个方便阅读的文档呢? 李四:一个方法一个方法地写呗,就像写Excel文档一下. 张三:啊,你out了,这多慢呀.为什么不玩玩doxygen工具,它能帮你生成文 ...
- ajax 发送请求无法重定向问题
原因: ajax请求默认就是不支持重定向的,因为它是局部刷新,不重新加载页面. 解决方案: 开发中需要多处使用重定向的情况下,大多都是在Spring mvc 的拦截器中,或过滤器中使用,此方法是在sp ...
- UiwebView and html
基础篇: NSURL介绍 http://blog.csdn.net/ysy441088327/article/details/7416759 网页执行js代码 复制代码 stringByEvalu ...
- FMDB数据库框架
nFMDB nFMDB n什么是FMDB pFMDB是iOS平台的SQLite数据库框架 pFMDB以OC的方式封装了SQLite的C语言API p nFMDB的优点 p使用起来更加面向对象,省去 ...
- ITFriend创业败局(序):简要概述我的第一次创业经历
是时候, 面对过去,继续踏上未来之路了. 是时候,该给自己一个交待了,给ITFriend创业合伙人.ITFriend用户.关注我的朋友和网友们一个答复了. 是时候,全面认真总结过去的经历. ...
- oracle中imp导入数据中文乱码问题(转)
(转自 http://blog.chinaunix.net/uid-186064-id-2823338.html) oracle中imp导入数据中文乱码问题 用imp命令向oracle中导入数据后, ...