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 ...
随机推荐
- java_第一年_JDBC(6)
DataBaseMetaData对象:由Connection.getDataBaseMetaData()方法获得,可以用来获取数据库的元数据,提供的方法有: getURL():返回一个String类, ...
- c++知识点总结3
http://akaedu.github.io/book/ week1 引用:相当于变量的别名.下面r和n就相当于同一回事 ; int &r=n; 引用做函数参数: void swap(int ...
- Ubuntu14 vsftp 的安装和虚拟用户配置
一.介绍 FTP 是 File Transfer Protocol (文件传输协议)的缩写 ,在 Unix/Linux 系统中常用的免费 FTP 服务器软件主要是 VSFTP,vsftp的官方地址:h ...
- day01-html
HTML概述: HTML: Hyper Text Markup Language 超文本标记语言 超文本: 比普通文本功能更加强大,可以添加各种样式 标记语言: 通过一组标签.来对内容进行描述. &l ...
- R语言封装函数
R语言封装函数 原帖见豆瓣:https://www.douban.com/note/279077707/ 一个完整的R函数,需要包括函数名称,函数声明,函数参数以及函数体几部分. 1. 函数名称,即要 ...
- Linux--shell交互输入与循环语句--06
一.交互输入 1.命令用法:read a b c -> aa bb cc read命令同时可以定义多个变量值:而输入的内容默认以空格为分隔符,将值输入到对应的变量中:如果默认值输入过多,最后 ...
- Git命令——撤销修改
Git命令 1. 撤销修改 (1) 当改乱了工作区(working directory)某个文件的内容,想直接丢弃工作区中的修改时,用命令git checkout -- file. (2) 当不但改乱 ...
- django之数据模型类的字段分析
一:表一的字段分析 class Sheep_Area(models.Model):# models.AutoField()自增列,要显示自定义的自增列,必须定义primary=True# area_i ...
- 19.go语言基础学习(下)——2019年12月16日
2019年12月16日16:57:04 5.接口 2019年11月01日15:56:09 5.1 duck typing 1. 2. 接口 3.介绍 Go 语言的接口设计是非侵入式的,接口编写者无须知 ...
- element-ui 里面el-checkbox多选框,实现全选单选
data里面定义了 data:[], actionids:[],//选择的那个actionid num1:0,//没选择的计数 num2:0,//选中的计数 ...