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. wikioi 1051哈希表

    题目描写叙述 Description 给出了N个单词,已经按长度排好了序.假设某单词i是某单词j的前缀,i->j算一次接龙(两个同样的单词不能算接龙). 你的任务是:对于输入的单词,找出最长的龙 ...

  2. POJ 1258 Agri-Net|| POJ 2485 Highways MST

    POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...

  3. [内核编程] Windebug双机调试环境搭建

    Windebug双机调试环境搭建    开始进行内核编程/驱动编程的调试工作是非常烦人的,由于程序运行与内核层不受操作系统的管控,所以容易引起主机蓝屏和崩溃是常有的事.这也就使得内核程序的调试成了一大 ...

  4. Nginx+uswgi+Django部署

    详情参考: http://blog.csdn.net/a_little_snail/article/details/78045636

  5. NSOperationQueue小结

    将建立的线程增加队列之中.他们都是并发运行的  假设想有一个线程在另外一个线程之后再运行的话 有一个方法能够实现- (void)addDependency:(NSOperation *)op; 这一个 ...

  6. 小强的HTML5移动开发之路(33)—— jqMobi基础

    一.什么是jqMobi jqMobi是由appMobi针对HTML5浏览器和移动设备开发的javascript框架,是个极快速的查询选择库,支持W3C查询. 版本 jqMobi源码最初在2012年1月 ...

  7. Architectures for concurrent graphics processing operations

    BACKGROUND 1. Field The present invention generally relates to rendering two-dimension representatio ...

  8. MVVM初步搭建应用

    MVVM模式:利用 prism Microsoft.Practices.Prism.dllWPF Interaction框架简介 添加Interactions库的引用.主要添加如下两个DLL: Mic ...

  9. js css 实现简单的计算器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Android 对.properties文件的读取

    /** * * @param filepath .properties文件的位置 */ public void checkFileExists(String filepath){ File file ...