zoukankan      html  css  js  c++  java
  • hdu 1244 Max Sum Plus Plus Plus

    Max Sum Plus Plus Plus

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 946    Accepted Submission(s): 467 

    Problem Description
    给定一个由n个正整数组成的整数序列
    a1 a2 a3 ... an
    求按先后次序在其中取m段长度分别为l1、l2、l3...lm的不交叠的连续整数的和的最大值。
     
    
    
    Input
    第一行是一个整数n(0 ≤ n ≤ 1000),n = 0表示输入结束 第二行的第一个数是m(1 ≤ m ≤ 20), 第二行接下来有m个整数l1,l2...lm。 第三行是n个整数a1, a2, a2 ... an.
     
    
    
    Output
    输出m段整数和的最大值。
     
    
    
    Sample Input
    3 2 1 1 1 2 3 4 2 1 2 1 2 3 5 0
     
    
    
    Sample Output
    5 10
     
    
    
    Author
    JGShining(极光炫影)
     
    
    
    Recommend
    Ignatius.L

    // 因为都是正整数 所以可以利用前缀和
    // dp[i][j] 代表在长度为j的序列中 切成i段的最大值
    #include <iostream> #include <algorithm> #include <queue> #include <math.h> #include <stdio.h> #include <string.h> using namespace std; int dp[25][1010]; int M[25]; int sum[1010]; int main() { int n,m; int in; int i,j,k; while(scanf("%d",&n),n){ scanf("%d",&m); for(i=1;i<=m;i++) scanf("%d",&M[i]); for(i=1;i<=n;i++){ scanf("%d",&in); sum[i]=sum[i-1]+in; } int l=0; memset(dp,0,sizeof(dp)); for(i=1;i<=m;i++){ l+=M[i]; for(j=l;j<=n;j++) dp[i][j]=max(dp[i][j-1],dp[i-1][j-M[i]]+sum[j]-sum[j-M[i]]); } printf("%d ",dp[m][n]); } return 0; }
  • 相关阅读:
    python之爬虫(九)PyQuery库的使用
    python之爬虫(八)BeautifulSoup库的使用
    Python之爬虫(七)正则的基本使用
    DropZone(文件上传插件)
    Django之自带分页模块Pagination
    Django之重写用户模型
    python--员工信息管理系统编译及思路
    python--生成器进阶
    python--迭代器与生成器
    python--简易员工信息系统编写
  • 原文地址:https://www.cnblogs.com/372465774y/p/3180272.html
Copyright © 2011-2022 走看看