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(动态规划)的更多相关文章

  1. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  2. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

  3. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  4. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  5. C#动态规划查找两个字符串最大子串

     //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {            ...

  6. C#递归、动态规划计算斐波那契数列

    //递归         public static long recurFib(int num)         {             if (num < 2)              ...

  7. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  8. 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划

    [BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...

  9. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

随机推荐

  1. SCUT - 271 - CC 非诚勿扰 - FFT

    https://scut.online/p/271 第一次遇到没这么裸的,其实感觉到是卷积但是不知道怎么化.看来以后要多注意下标. #include <bits/stdc++.h> usi ...

  2. MVC调用函数function.php

    <?php //控制器的调用函数C function C($name, $method){ require_once('/libs/controller/'.$name.'Controller. ...

  3. Untiy3D按方向键获取值

    一,如下代码 float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical" ...

  4. jquery 使用a标签导航栏跳转页面,动态添加高亮

    众所周知,使用a标签跳转之后,会刷新一次,继而这个添加的样式就会消失.那么怎么解决这一问题呢? <script> $(function () { $('.bar a').each(func ...

  5. ReentrantReadWriteLock实现原理

    在java并发包java.util.concurrent中,除了重入锁ReentrantLock外,读写锁ReentrantReadWriteLock也很常用.在实际开发场景中,在使用共享资源时,可能 ...

  6. MT41J256M16HA-125 原厂订购 现货销售

    作为一家科研公司,保证芯片的原厂品质和正规采购渠道是科学严谨的研发工作中重要的一环,更是保证研发产品可靠.稳定的基础.而研发中所遇到的各种不可预测的情况更是每个工程师向技术的山峰攀登中时会遇到的各种难 ...

  7. CentOS 7 FTP的安装与配置

    CentOS7 FTP安装与配置 1.FTP的安装 #安装yum install -y vsftpd #设置开机启动systemctl enable vsftpd.service #启动systemc ...

  8. idea import class的快捷键

    有自动import class的快捷键 设置如下: 1.alt+enter 2.写好代码之后ctrl+alt+l格式化代码,优化导入包   1.alt+enter 2.写好代码之后ctrl+alt+l ...

  9. alert(1) to win 12

  10. php session之多级目录存储

    当选择以文件形式保存session到服务器时,需要制定保存路径.用到php.ini中的session.save_path,其有三种配置写法: session.save_path = "N;/ ...