[题目传送门](http://acm.hdu.edu.cn/showproblem.php?pid=1024)//res tp hdu

数据范围1e6,若是开二维会爆

考虑用滚动数组优化

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i = (a);i>=(b);--i)
#define fo(i,a,b) for(int i =(a);i<(b);++i)
#define de(x) cout<<#x<<" = "<<x<<endl;
#define endl '\n'
#define ls(p) ((p)<<1)
#define rs(p) (((p)<<1)|1)
using namespace std;
typedef long long ll;
const int mn = 1e6+10;
// search m seg to make the sum of them max
//1e6, more than one test
ll arr[mn];
ll dp[mn],pre[mn];
// 滚动数组优化二维dp
int main(){
int n,m;
while(scanf("%d %d",&m,&n)!=EOF){
rep(i,1,n) scanf("%lld",&arr[i]);
//dp[i][j] = max(dp[i][j-1]+arr[j],max(dp[i-1][k])+arr[j]) (1 <=k<=j-1)
ll MAX;
rep(i,1,n) dp[i] = pre[i] = 0;
rep(i,1,m){
MAX = -1e9; // max in [1,j-1]
rep(j,i,n){
dp[j] = max(dp[j-1],pre[j-1])+arr[j];
pre[j-1] = MAX;
MAX = max(MAX,dp[j]);
}
}
printf("%lld\n",MAX);
}
}

最新文章

  1. java和python细节总结和java中string 的+操作
  2. 【HDOJ】2526 浪漫手机
  3. java设计模式--结构型模式--代理模式
  4. Servlet之会话(Session)以及会话追踪技术(Cookie),(URL重写)和(隐藏表单域)
  5. 搞懂MySQL InnoDB事务ACID实现原理
  6. Win10一周年纪念版,瞧一瞧Linux子系统
  7. (转)git checkout 撤销修改
  8. WDTP注册破解
  9. LeetCode 27 Remove Element (移除数组中指定元素)
  10. 运行 命令框不记录打过的命令,重启后CMD里面是空的.上次打过的命令消失了.
  11. 调用数据库-corina
  12. 【BZOJ1630/2023】[Usaco2007 Demo]Ant Counting DP
  13. s3对象存储
  14. ppt修改默认字体
  15. C#使用WebService
  16. Redis-3.2.0集群配置(redis cluster)
  17. NOIP 2014 提高组 Day1
  18. hdfs启动后进入safe mode,Problem connecting to server
  19. 使用sha512算法加密linux密码
  20. scikit-learn入门学习记录

热门文章

  1. E.Substring Reverse Gym - 101755E
  2. 学院管理系统(mysql版)
  3. LinkedBlockingQueue和ArrayBlockingQueue的异同
  4. 初学Linux之标准I/O和管道
  5. 第二章 c语言概述
  6. office很抱歉遇到一些临时服务器问题
  7. [oracle]oracle表在什么情况下会被锁住(转载)
  8. 2.5 Go语言基础之map
  9. 005-多线程-锁-JUC锁-LockSupport【使用、Unsafe、对比Object的wait、底层源码】
  10. c++ throw异常(学习)