hdu2182青蛙

一只名为Fog的青蛙在回家的路上要吃掉路径上的昆虫。青蛙可以在坐标0开始,跳T个单位的距离,A≤T≤B,并且每跳K次就会累。输入包含路径长度、跳跃范围和体力值,以及每个位置的昆虫数。求青蛙最多能吃多少只昆虫。解题策略是使用动态规划计算每次跳跃到不同位置的最大昆虫数量。
摘要由CSDN通过智能技术生成

题目:hdu2182青蛙

Frog
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2264 Accepted Submission(s): 1003

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

题目大意:一个区间大小为0-n-1的区域中,每个位置都有一定数量的虫子,有一只青蛙有k的体力值,每次跳跃会消耗1体力值,所有体力值消耗完就不能跳跃,每次跳跃能跳跃长度的范围为a-b.
解题思路:因为第i次跳跃到某个位置能取的最大值由该位置j往前[j-b,j-a]区间内第i-1次跳跃取得的最大值再加上j位置的虫子数,得动态转移方程:dp[i][j] = max(dp[i][j], dp[i - 1][k]); (j-b<k<j-a),dp[i][j]表示第i次跳跃到j位置后能吃到虫子的最大值,

AC代码:

#include<iostream>
#include<stdio.h>
#
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值