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; }
  • 相关阅读:
    【CCF】高速公路 tarjan强连通缩点
    【hihocoder】欧拉路径 并查集判连通
    【CCF】地铁修建 改编Dijkstra
    Android仿微信朋友圈图片展示实现
    android 禁止 recycler 滑动
    android中关闭软键盘
    java Math.pow 精度丢失问题
    Centos查看端口占用情况和开启端口命令
    centos 部署 php
    php undefinde function json_decode()
  • 原文地址:https://www.cnblogs.com/372465774y/p/2609367.html
Copyright © 2011-2022 走看看