链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024

 #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<unordered_map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e6+;
int dp[maxn],Max[maxn],a[maxn];
int m,n;
int main(){
while(scanf("%d%d",&m,&n)!=EOF){
for(int i = ;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
memset(Max,,sizeof(Max));
int temp = ;
for(int i = ;i<=m;i++){
temp = -inf;
for(int j = i;j<=n;j++){
dp[j] = max(dp[j-] , Max[j-]) + a[j]; //dp[j]表示前j个数构成i个子段的最大和
Max[j-] = temp; //Max[j-1]表示前j - 1个数构成 i - 1个子段的最大和
temp = max(temp,dp[j]);//temp做为中间值去记录Max[j-1], 方便循环的下一次更新Max[j-1]
}
}
printf("%d\n",temp);
}
return ;
}

最新文章

  1. c#使用json接口
  2. 《Matrix Computation 3rd》读书笔记——第3章 一般线性系统
  3. List接口
  4. UE4.11新特性:胶囊体阴影
  5. xamarin.ios 实现圆形进度条
  6. [转]玩转Google开源C++单元测试框架Google Test系列
  7. linux C之access函数 (20
  8. [行业关键词] review code review
  9. Hibernate的load()和get()区别
  10. mac电脑操作
  11. linux应用以及常用命令
  12. java学习笔记-输入输出流
  13. git打tag
  14. java框架篇---hibernate(多对多)映射关系
  15. WinForm之窗体应用程序
  16. [UE4]网络游戏重点思考
  17. thinkphp5 URL的访问
  18. Broadcast总结 service
  19. NBUT 1221 Intermediary
  20. zoj3696(泊松分布)

热门文章

  1. CF 150E Freezing with Style [长链剖分,线段树]
  2. take it away `electron-builder` Electron打包失败的问题
  3. 案例-pyqt进度条案例
  4. Keras高层API之Metrics
  5. openlayers轨迹匀速播放
  6. sql注入文件写入和读取
  7. 洛谷P1402 酒店之王(网络流)
  8. 851. spfa求最短路(spfa算法模板)
  9. npm 基础命令
  10. Subway POJ - 2502 spfa