Frog

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 712    Accepted Submission(s): 338

Problem Description
A little frog named Fog is on his way home. The path's length is N (1 <= N <= 100), and there are many insects along the way. Suppose the


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.

 
Input
The input consists of several test cases.

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
each test case:

Output one line containing an integer - the maximal number of insects that Fog can eat.

 
Sample Input
1
4 1 2 2
1 2 3 4
 
Sample Output
8
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2110 

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)的更多相关文章

  1. hdu 4576 (简单dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...

  2. hdu 5037 Frog 贪心 dp

    哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...

  3. HDU 2836 Traversal 简单DP + 树状数组

    题意:给你一个序列,问相邻两数高度差绝对值小于等于H的子序列有多少个. dp[i]表示以i为结尾的子序列有多少,易知状态转移方程为:dp[i] = sum( dp[j] ) + 1;( abs( he ...

  4. 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 ...

  5. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. 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 ...

  7. HDU 5375 Gray code (简单dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Oth ...

  8. hdu 2084 数塔(简单dp)

    题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...

  9. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

随机推荐

  1. php curl header头

    工作中第一次用到header做个记录 工作中需要在heaer里面加上 Authorization 用来验证身份 public function index() { $url = "http: ...

  2. ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩

    一:MiMEType:一般可以再百度上搜索到相应文件的MiMEType,或是利用c语言的api去获取文件的MiMEType : //对该文件发送一个异步请求,拿到文件的MIMEType - (void ...

  3. iOS开发之Quarz2D:九:图形上下文矩阵操作

    #import "VCView.h" @implementation VCView - (void)drawRect:(CGRect)rect { // Drawing code ...

  4. hash_map原理及C++实现

    一.数据结构:hash_map原理  hash_map基于hash table(哈希表).哈希表最大的长处,就是把数据的存储和查找消耗的时间大大减少,差点儿能够看成是常数时间:而代价不过消耗比較多的内 ...

  5. 【35.43%】【hdu 4347】The Closest M Points

    Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submissio ...

  6. 基于 MySQL 5.6 keepalived的双主搭建

    环境介绍: 说明 IP 节点1 192.168.56.56 节点2 192.168.56.57 w_ip 192.168.56.6 安装keepalived tar -zxvf keepalived- ...

  7. ag

    https://github.com/k-takata/the_silver_searcher-win32/releases http://betterthanack.com/https://gith ...

  8. 定时清理tomcat日志文件

    原文链接:https://blog.csdn.net/qq_37936542/article/details/78788466 需求:最近公司服务器发现磁盘经常会被占满,查其原因是因为大量的日志文件. ...

  9. 详解PHP设置定时任务的实现方法

    详解PHP设置定时任务的实现方法 一.总结 一句话总结: 1.ignore_user_abort(true)是什么意思? 无论客户端是否关闭浏览器,下面的代码都将得到执行 2.set_time_lim ...

  10. arm-linux内存管理学习笔记(1)-内存页表的硬件原理

    linux kernel集中了世界顶尖程序猿们的编程智慧,犹记操作系统课上老师讲操作系统的四大功能:进程调度 内存管理 设备驱动 网络.从事嵌入式软件开发工作,对设备驱动和网络接触的比較多. 而进程调 ...