zoukankan      html  css  js  c++  java
  • 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()


    作者:孙建钊
    出处:http://www.cnblogs.com/sunjianzhao/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    android PopupWindow实现从底部弹出或滑出选择菜单或窗口
    AndroidUI开源组件库BottomView 第三方自定义UI控件
    Android LayoutInflater详解
    Android设置上下边框或者左右边框
    杭州驾校模拟考试
    告诉你LTE-FDD与LTE-TDD的区别
    Android-Uiautomator:[5]停止monkey测试
    Android WebView
    解决Item控件抢占焦点
    ACM-计算几何之Quoit Design——hdu1007 zoj2107
  • 原文地址:https://www.cnblogs.com/sunjianzhao/p/11383585.html
Copyright © 2011-2022 走看看