hdu2182Frog(动态规划)
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
无脑的dpAC代码:
include
include
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int N,A,B,K;
cin>>N>>A>>B>>K;
int a[120]={0};
for(int i=0;i<N;i++)
cin>>a[i];
int dp[120][120]; //dp[i][k]表示在第i+1个位置的第k次跳后的最大值
memset(dp,-1,sizeof(dp));
dp[0][0]=a[0];
for(int i=0;i<N;i++)
{
for(int j=A;j<=B;j++)
{
for(int k=0;k<=max(K,101);k++)
{
if(dp[i][k]!=-1&&i+j<N) dp[i+j][k+1]=max(dp[i][k]+a[i+j],dp[i+j][k+1]);
else continue;
}
}
}
int max1=0;
for(int i=0;i<N;i++)
{
for(int j=1;j<=K;j++)
{
if(dp[i][j]>max1) max1=dp[i][j];
}
}
cout<<max1<<endl;
}
return 0;
}
但凡使用dp的,稍微有点难度的基本都会用到max()
hdu2182Frog(动态规划)的更多相关文章
- 增强学习(三)----- MDP的动态规划解法
上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...
- 简单动态规划-LeetCode198
题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- 动态规划之最长公共子序列(LCS)
转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...
- C#动态规划查找两个字符串最大子串
//动态规划查找两个字符串最大子串 public static string lcs(string word1, string word2) { ...
- C#递归、动态规划计算斐波那契数列
//递归 public static long recurFib(int num) { if (num < 2) ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
[BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
随机推荐
- python学习第四十五天__name__用法和作用
在python导入模块导入另外一个模块的时候,有时候只是想用其一个方法,会出现其他的方法也运行了,python用到__name__==‘__main__’ 解决问题,那么__name__用法和作用 1 ...
- Elasticsearch7.X 入门学习第一课笔记----基本概念
原文:Elasticsearch7.X 入门学习第一课笔记----基本概念 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https: ...
- vue主动刷新页面及列表数据删除后的刷新方法
在继刷新当前页面,重载页面数据那篇之后 那一篇 深入理解数据驱动 以上算是开发过程中的一个坑,用了一段时间,今天再读代码的时候,感觉被坑的很严重. 1. 获取列表方法 2.重新获取数据 3.这样再次调 ...
- Dubbo学习源码总结系列五--集群负载均衡
Dubbo提供了哪些负载均衡机制?如何实现的? LoadBalance接口:可以看出,通过SPI机制默认为RandomLoadBalance,生成的适配器类执行sel ...
- Python Paramiko模块使用
1 执行远程命令 #!/usr/bin/python import paramiko ssh = paramiko.SSHClient() ssh.set_missing_host_key_polic ...
- Oracle 索引数据字典、基于函数的索引
user_indexes 字典视图包含了索引名和唯一性, user_ind_columns视图包含了索引名.表名.以及列名 dba_indexes dba_ind_columns 同理 select ...
- Fiddler过滤css、js、图片等静态文件
REGEX:(?insx)/[^\?/]*\.(css|ico|jpg|png|gif|bmp|wav)(\?.*)?$ REGEX:(?insx)/[^\?/]*\.(action|do)(\?.* ...
- cmd获取管理员权限等
鼠标点点点的略过 可输入命令 runas /user:Administrator cmd 或 runas /noprofile /user:Administrator cmd Administrato ...
- man uname
UNAME(1) User Commands/用户命令 UNAME(1) NAME/名称 uname - print system information/打 ...
- [NOIP2014]飞扬的小鸟[DP]
[NOIP2014]飞扬的小鸟 ——!x^n+y^n=z^n 题目描述: Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画 ...