hdu 2128 Frog(简单DP)
2015-08-07 11:40
351 查看
Frog
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 712 Accepted Submission(s): 338
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
each test case:
Output one line containing an integer - the maximal number of insects that Fog can eat.
[align=left]Sample Input[/align]
1 4 1 2 2 1 2 3 4
[align=left]Sample Output[/align]
8
[align=left]Source[/align]
field=problem&key=ECJTU%202008%20Summer%20Contest&source=1&searchmode=source">ECJTU 2008 Summer Contest
[align=left]Recommend[/align]
lcy | We have carefully selected several similar problems for you: 2110 2191 2175 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; }
相关文章推荐
- coredump调试的使用
- jquery的匿名函数研究
- 初来乍到
- 字典树的基本知识及使用C语言的相关实现
- java后台 jstl输出数据库表中的一组数据&&jstl输出数据库表中的所有数据并放在List集合
- fis3-learn - 2 配置篇
- 数据库表的创建、管理和数据操作(实验一)
- fis_learn_内置语法_3
- 利用ffmpeg将H264流 解码为RGB
- 利用ffmpeg将H264流 解码为RGB
- Golang适合高并发场景的原因分析
- IE和火狐的兼容问题汇总
- 46. Element isEqualNode() 方法
- java设计模式-command模式
- 利用ffmpeg将H264流 解码为RGB
- EXCEL帮助类
- lua本学习笔记功能
- Android手机提示“未安装应用程序”
- 记一些浏览器缓存以前不太熟悉的东西
- 利用ffmpeg将H264流 解码为RGB 分类: VC++ ffmpeg-SDL-VLC-Live555 2015-08-07 11:39 155人阅读 评论(0) 收藏