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. 用strace排查故障的5种简单方法(每日一译)

    原文链接:5 simple ways to troubleshoot using Strace 我很意外大部分人都不知道如何使用strace.strace一直是我的首选debug工具,因为它非常的有效 ...

  2. php压缩

    php压缩的一个demo,随便测试了一下,可以用 <?php class PHPZip { private $ctrl_dir = array(); private $datasec = arr ...

  3. [Angular] Test Directive

    directive: import { Directive, HostListener, HostBinding, ElementRef } from '@angular/core'; @Direct ...

  4. windows程序扫雷程序设计

    详细资源见:http://download.csdn.net/detail/zhouyelihua/7604765 在学习windows程序设计中.我们希望通过一个完整的程序来学习windows AP ...

  5. [JS Compose] 6. Semigroup examples

    Let's we want to combine two account accidently have the same name. , friends: ['Franklin'] } , frie ...

  6. Android图表和图形创建库:EazeGraph

    EazeGraph是一个 Android 库用于创建漂亮和花哨的图表.它具有易于使用和高度可定制的特点.当前支持四种不同的图表如下: Chart types Bar Chart Stacked Bar ...

  7. [Angular] Adding keyboard events to our control value accessor component

    One of the most important thing when building custom form component is adding accessbility support. ...

  8. 微信小程序从零开始开发步骤(四)

    上一章节,实现了小程序的底部导航的功能,这一节开始实现一些简单的功能.本章节介绍的是小程序的自定义分享的功能. 可以分享小程序的任何一个页面给好友或群聊.注意是分享给好友或群聊,并没有分享到朋友圈.一 ...

  9. 使用SecureCRT连接AWS的EC2

    如果使用CentOS等linux系统,直接使用ssh命令即可访问AWS上的Linux-EC2实例. $ ssh -i XXX.pem ec2-user@{IP/hostname} 在Windows系统 ...

  10. 【u203】文件夹计数

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 可以用路径来描述文件夹,路径为一个包含若干部分的字符串,之间用'/'分隔.每部分均为一个文件夹的名称, ...