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