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. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. [Docker] Run Short-Lived Docker Containers

    Learn the benefits of running one-off, short-lived Docker containers. Short-Lived containers are use ...

  3. MS SQL Server的STRING_SPLIT和STRING_AGG函数

    在较新版本的SQL中,出现有2个函数,STRING_SPLIT和STRING_AGG,前者是把带有分隔的字符串转换为表,而后者却是把表某一表转换为以某种字符分隔的字符串. 如下面: DECLARE @ ...

  4. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  5. 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(5)有趣的指针

    一.指针是C语言的灵魂 # include <stdio.h> int main(){ int *p; //p是变量名,int *表示p变量存放的是int类型变量的地址,p是一个指针变量 ...

  6. hdu3461Marriage Match IV 最短路+最大流

    //给一个图.给定起点和终点,仅仅能走图上的最短路 //问最多有多少种走的方法.每条路仅仅能走一次 //仅仅要将在最短路上的全部边的权值改为1.求一个最大流即可 #include<cstdio& ...

  7. 【iOS】怎样推断文本文件的字符编码格式

    整体思路: 遍历全部的字符编码.能正确读取输出转换的就是文本文件的编码格式. 代码例如以下: // // main.m // 检測文本字符编码格式的小技巧 // // Created by 杜子兮 ( ...

  8. Android 带清除功能的输入框控件EditTextWithDel

    记录下一个非常有用的小控件EditTextWithDel.就是在Android系统的输入框右边增加一个小图标.点击小图标能够清除输入框里面的内容,由于Android原生EditText不具备此功能,所 ...

  9. 【t019】window(单调队列)

    Time Limit: 2 second Memory Limit: 256 MB [问题描述] 给你一个长度为N 的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右 ...

  10. Hierarchical Tree Traversal in Graphics Pipeline Stages

    BACKGROUND Many algorithms on a graphics processing unit (GPU) may benefit from doing a query in a h ...