zoukankan      html  css  js  c++  java
  • hdu 2182 Frog

    Frog

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 492    Accepted Submission(s): 221


    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
     
    
    
    Source
     
    
    
    Recommend
    lcy
    //动态规划,背包问题

    #include
    <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <queue> #include <cmath> using namespace std; int dp[103]; int rc[103]; int main() { int T; int i,j,k; int N,A,B,K; scanf("%d",&T); int l,r; while(T--) { scanf("%d%d%d%d",&N,&A,&B,&K); for(i=0;i<N;i++) scanf("%d",&rc[i]); memset(dp,0,sizeof(dp)); dp[0]=rc[0]; while(K--) { for(j=N-1;j>=A;j--) { l=j-B;r=j-A; if(l<0) l=0; for(;l<=r;l++) if(dp[l]!=0) { dp[j]=dp[l]+rc[j]>dp[j]?dp[l]+rc[j]:dp[j]; } } } k=0; for(i=0;i<N;i++) if(dp[i]>k) k=dp[i]; printf("%d\n",k); } return 0; }
  • 相关阅读:
    德信创业系2014版
    [学习笔记]矩形面积并
    第六章 深入分析ClassLoader工作机制
    第五章 深入class文件结构
    设计模式
    第四章 Javac编译原理
    第三章 深入分析Java Web中的中文编码问题
    第2章 深入分析java I/O的工作机制(下)
    linnx常用命令学习
    jenkins学习(1)
  • 原文地址:https://www.cnblogs.com/372465774y/p/2609367.html
Copyright © 2011-2022 走看看