HDU 2128 Frog (simple DP)

Source: Internet
Author: User

FrogTime limit:3000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 712 Accepted Submission (s): 338


Problem Descriptiona Little frog named Fog is on the his-a-home. The path ' s length is n (1 <= n <=), and there is many insects along the the. Suppose the
Original coordinate of Fog is 0. Fog can stay still or jump forward T units, A <= t <= B. Fog would eat up all the insects wherever he stays, but he w Ill
Get tired after K-jumps and can not-jump no more. The number of insects (always less than 10000) in each position of the path is given.
How many insects can Fog eat at the most?
Note that Fog can only jump within the range [0, N], and whenever he jumps, his coordinate increases.

Inputthe 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.
Outputeach test Case:
Output one line containing a integer-the maximal number of insects that Fog can eat.

Sample Input

Sample Output
8

Source

Field=problem&key=ecjtu%202008%20summer%20contest&source=1&searchmode=source ">ECJTU Summer Contest
Recommendlcy | 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

Test instructions

A certain number of worms val[i per unit length on the road of length n]. Now a frog starts at position 0 (position from 0 to N-1).

It can jump at a distance of [a, b] range and it either jumps forward or does not jump.

And it can jump a maximum of k times. Every place a frog eats a worm in that place. Now tell you the number of bugs in every place ask you how many bugs it can eat.

Ideas:

DP[I][J] Indicates the maximum number of bugs eaten by J-step when the frog jumps to the first position.

Then Dp[i][j]=max (Dp[i-k][j-1]) +val[i]. A<=k<=b.

Let the post-recursive push.

See the code for details:

#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++)//Note range                    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;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Hdu 2128 Frog (simple DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.