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

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

field=problem&key=ECJTU%202008%20Summer%20Contest&source=1&searchmode=source">ECJTU 2008 Summer Contest

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;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

时间: 2024-08-29 18:03:57

hdu 2128 Frog(简单DP)的相关文章

HDU 1158【简单dp】

题意:给你一个项目,需要几个月来完成买,同时也给你每个月最少需要的工人数.并且告诉你hiring,firing每个工人的钱数,以及每个月应付每个工人的工资.求项目完成时最小花费. 这是个简单dp,思路就是枚举一下上一个月和本月的工人数,写个状态转移方程即可. #include<stdio.h> #include<string.h> #include<queue> #include<iostream> #define MAX 6000 #define INF

hdu 5037 Frog 贪心 dp

哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 454    Accepted Submission(s): 96 Problem

hdu 5569 matrix(简单dp)

Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at first , you begin with the number at top-left corner (1,1) and you want to go to the number at bottom-right corner (n,m). And you must go right or go down every

HDU 2571【简单dp】

刚开始的时候错在了第一行第一列的转移. 注意:第一行第一列上的数据只能由该行或者该列转移,因为他是从(1,1)这个点出发的,不是任意的点出发的. 所以除了dp[1][0],dp[0][1],其他dp值都要初始化为-INF #include<stdio.h> #include<string.h> #include<iostream> #define MAX 1000+10 #define INF 0x1f1f1f1f using namespace std; int dp

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题

听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到100即可 算最大GPA的时候,首先每个科目分配到60分,然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到85即可,如果还有REMAIN POINT,就FOR循环下来加到100上限即可 不会DP 阿 QAQ 过段时间得好好看DP了  =  = 于是默默的把这题标记为<水题集> //

HDU 4826 简单DP

Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向上向下向右走以前没有走过的格子,每一个格子中都有一些金币(或正或负,有可能遇到强盗拦路抢劫,度度熊身上金币可以为负,需要给强盗写欠条),度度熊刚开始时身上金币数为0,问度度熊走出迷宫时候身上最多有多少金币? Input 输入的第一行是一个整数T(T < 200),表示共有T组数据.每组数据的

HDU 4960 Another OCD Patient 简单DP

思路: 因为是对称的,所以如果两段是对称的,那么一段的前缀和一定等于另一段的后缀和.根据这个性质,我们可以预处理出这个数列的对称点对.然后最后一个对称段是从哪里开始的,做n^2的DP就可以了. 代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algori

hdu 1520Anniversary party(简单树形dp)

Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4310    Accepted Submission(s): 1976 Problem Description There is going to be a party to celebrate the 80-th Anniversary of the