m的范围没给,很坑爹

Max Sum Plus Plus

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

Problem Description
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define a function sum(i, j) = Si + ... + Sj (1 ≤ i ≤ j ≤ n).

Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx is not allowed).

But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(ix, jx)(1 ≤ x ≤ m) instead. ^_^

 
Input
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
Process to the end of file.
 
Output
Output the maximal summation described above in one line.
 
Sample Input
1 3 1 2 3
2 6 -1 4 -2 3 -2 3
 
Sample Output
6
8

Hint

Huge input, scanf and dynamic programming is recommended.

 
Author
JGShining(极光炫影)
 
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <map>
  7. #include <queue>
  8. #include <sstream>
  9. #include <iostream>
  10. using namespace std;
  11. #define INF 0x3fffffff
  12. typedef __int64 LL;
  13. #define N 1000100
  14.  
  15. LL dp[N][];
  16. LL g[N];
  17.  
  18. int main()
  19. {
  20. //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
  21. //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
  22. int m,n;
  23. while(scanf("%d%d",&m,&n)!=EOF)
  24. {
  25. for(int i=;i<=n;i++)
  26. {
  27. g[i]=-;
  28. dp[i][]=dp[i][]=-;
  29. }
  30. int a=,b=;
  31. for(int i=;i<=n;i++)
  32. {
  33. swap(a,b);
  34. int tmp;
  35. scanf("%d",&tmp);
  36. for(int j=m;j>=;j--)
  37. {
  38. if(j>i) continue;
  39. dp[j][a]=max(dp[j][b],g[j-])+tmp;
  40. if(dp[j][a] > g[j]) g[j] = dp[j][a];
  41. }
  42. }
  43. printf("%I64d\n",g[m]);
  44. }
  45. return ;
  46. }

hdu1024(最大m串子序列)的更多相关文章

  1. 【BZOJ】2086: [Poi2010]Blocks

    题意 \(n(1 \le n \le 1000000)\)个数\(a_i(a_i \le 10^9)\).\(m(1 \le m \le 50)\)次询问,每次给出一个\(k(k \le 10^9)\ ...

  2. 【HDU4632 Palindrome subsequence】区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...

  3. HDU4632:Palindrome subsequence(区间DP)

    Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...

  4. POJ 1458 Common Subsequence (zoj 1733 ) LCS

    POJ:http://poj.org/problem?id=1458 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=73 ...

  5. Parity game(带权并查集+离散化)

    题目链接  //kuangbin 题意: 现在你和你的朋友正在玩一种游戏. 你的朋友写下一串0和1的序列,然后你选择其中一串子序列(如[3,5])并且问他这个序列是包含奇数个1还是偶数个1(和是奇数还 ...

  6. 数据挖掘入门系列教程(九)之基于sklearn的SVM使用

    目录 介绍 基于SVM对MINIST数据集进行分类 使用SVM SVM分析垃圾邮件 加载数据集 分词 构建词云 构建数据集 进行训练 交叉验证 炼丹术 总结 参考 介绍 在上一篇博客:数据挖掘入门系列 ...

  7. Codeforces Round #661 (Div. 3) D、E1 题解

    D. Binary String To Subsequences #贪心 #构造 题目链接 题意 给定一个\(01\)串\(s\),完全分割成若干子序列(注意,不要混淆子串与子序列的概念),其中的子序 ...

  8. HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化

    题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...

  9. 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]

    [题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...

随机推荐

  1. quartus ii工程文件的分析

    .pof:通过AS口将程序固化到EPCS(flash)内. .sof:通过JTAG口下载到FPGA内部的SRAM里面. .JIC:通过JTAG口将程序固化到EPCS(flash)内.

  2. 使用 C# 开发智能手机软件:推箱子(十八)

    这是"使用 C# 开发智能手机软件:推箱子" 系列文章的第十八篇.在这篇文章中.介绍 Window/SelectLevelDlg.cs 源程序文件. 这个源程序文件包括 Selec ...

  3. Nginx 1.5.2 + PHP 5.5.1 + MySQL 5.6.10 在 CentOS 下的编译安装

    最近配置了几台Web服务器,将安装笔记贴出来吧.没时间像以前那样,将文章写的那样系统了,请见谅.详细配置,可以看以前的旧文章: http://blog.zyan.cc/nginx_php_v6 .安装 ...

  4. OS开发UI篇—UIWindow简单介绍

    一.简单介绍 UIWindow是一种特殊的UIView,通常在一个app中只会有一个UIWindow iOS程序启动完毕后,创建的第一个视图控件就是UIWindow,接着创建控制器的view,最后将控 ...

  5. git 的一些笔记

    git config git config存在三个地方 :1./.git/config 项目级别2.~/.gitconfig 用户级别3./etc/gitconfig 系统级别 git config ...

  6. iOS开发Swift篇—(七)函数

    iOS开发Swift篇—(七)函数 一.函数的定义 (1)函数的定义格式 1 func 函数名(形参列表) -> 返回值类型 { 2 // 函数体... 3 4 } (2)形参列表的格式 形参名 ...

  7. dp之完全背包poj3181(高精度背包)

    这个题目要用到大数的加法,其他的,我没有感觉到有什么难想的......比较水的背包题,掠过..... #include<iostream> #include<stdio.h> ...

  8. 基于HTML5 Canvas生成粒子效果的人物头像

    前面我们分享过一个HTML5 Canvas实现的图像马赛克模糊效果,HTML5处理图片真的非常简单.今天我们要再利用HTML5 Canvas实现一个粒子效果的人物头像,你可以任意选择一张头像图片,接下 ...

  9. Webpack实例教程及模块化规范

    Webpack 是当下最热门的前端资源模块化管理和打包工具.它能够将很多松散的模块依照依赖和规则打包成符合生产环境部署的前端资源. 通过 loader 的转换,不论什么形式的资源都能够视作模块,比方 ...

  10. Desugar Scala(16) -- Lower Bound

    欢迎关注我的新博客地址:http://cuipengfei.me/ Lower bound,不知道这个词的确切中文翻译是怎样的.我们直接看例子吧. 1 2 3 class Pair[T](val fi ...